这是我的代码
function exit_ajax($ex_return_value, $ex_ch=null, $ex_close_resource=false) {
$output = array('return' => $ex_return_value);
echo json_encode($output);
if ($ex_close_resource)
curl_close($ex_ch);
exit();
}
#ini_set("display_errors",1);
#error_reporting(E_ALL);
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']))
exit_ajax("server value unset");
if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest')
exit_ajax("server value bad");
$nickname = $_POST['nickname'];
$ch = curl_init();
if(!$ch)
exit_ajax("CURL_INIT_NULL", $ch, true);
curl_setopt($ch, CURLOPT_URL, "t.co");
curl_setopt($ch, CURLOPT_HTTPHEADER,array('User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($ch);
if (!$html) exit_ajax("Errors: curl_getinfo: " . curl_getinfo($ch) . "; curl_error: " . curl_error($ch) . "; curl_errno: " . curl_errno($ch), $ch, true);
$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
exit_ajax("all fine");
它通过来自某个页面的 ajax 调用执行。如果所需的站点已启动,则一切正常。如果它关闭 (502/504),则该脚本将永远运行。我要更改什么以使其返回 t/o 错误?