我需要一些幫助我試圖終止我的腳本,如果它達到60秒,如果它不能連接到服務器,但我總是抓住60秒限制執行時間。我想我的代碼不管用。在60秒內終止腳本
<?php
$time_limit = 60;
set_time_limit ($time_limit);
if(isset($_GET['comm'])){
$command = $_GET['comm'];
$host = "xxx.xx.xxx.xx";
$port = xxxx;
$start_time = time();
$message = $command;
$socket = socket_create(AF_INET, SOCK_STREAM,0) or die("Could not create socket\n");
while([email protected]_connect($socket, $host, $port)){
if ((time() - $start_time) >= $time_limit)
{
socket_close($socket);
die("Connection timed out.\n");
}
sleep(1);
continue;
}
socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
$resultserv = socket_read ($socket, 1024) or die("Could not read server response\n");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://tomysite/receive.php',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'recrespond' => $resultserv
)
));
$resp = curl_exec($curl);
curl_close($curl);
echo $resultserv;
socket_close($socket);
}
?>
在此先感謝您。
http://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-exceeded你也顯然不能設置超時在60時,這是PHP的時間限制以及它將需要在59. – mschuett 2014-09-23 02:18:11