1,curl进程运行了一个api查询接口,curl的时候设置了超时时间
--connect-timeout 1000
2,operation timed out after 1000 milliseconds
with 0 bytes received
3,connect() timed out!
连接超时时间用 –connect-timeout 参数来指定,数据传输的最大允许时间用 -m 参数来指定,时间是毫秒
curl --connect-timeout 10 -m 20 "http://***"
curl: (28) connect() timed out!
curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
//连接超时时间
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1000);
//数据传输的最大允许时间
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
//使用curl_error($ch)查看错误的详情
var_dump(curl_error($ch));
set_time_limit()
来控制运行时间,配置该页最久执行时间。max_execution_time
的值定义在结构档案中,如果将秒数设为0,表示无时间上的限制,修改后重新启动apache/nginx
服务器set_time_limit(800)
;max_execution_time
数值 - 当前脚本已经执行的时间 + 设定值php.ini
里的max_execution_time
=30,当前脚本已经执行5秒,则:set_time_limit( )
将不会有结果,除非是关闭安全模式或是修改结构档案中的时间限制。set_time_limit
来设置一个脚本的执行时间为无限长;然后使用flush()
和 ob_flush()
来清除服务器缓冲区,随时输出脚本的返回值。<?php
header("Content-Type: text/plain");
set_time_limit(0);
$infoString = "Hello World" . "\n";
while( isset($infoString) )
{
echo $infoString;
flush();
ob_flush();
sleep(5);
}
?>
Hello World
,如果不按停止按钮,浏览器会不停的一行一行继续加载。ps aux | grep -c php-fpm
/usr/bin/php -i|grep mem
/etc/init.d/php-fpm restart