我正在通过PHP对eXist数据库运行curl请求。数据集非常大,因此数据库始终需要很长时间才能返回XML响应。为了解决这个问题,我们设置了一个curl请求,并设置了一个应该很长的超时时间。
$ch = curl_init();
$headers["Content-Length"] = strlen($postString);
$headers["User-Agent"] = "Curl/1.0";
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'admin:');
curl_setopt($ch,CURLOPT_TIMEOUT,1000);
$response = curl_exec($ch);
curl_close($ch);
然而,通过curl请求时请求在完成之前就持续结束(<1000当通过浏览器请求时)。请问是否知道这是设置curl超时的正确方式?
set_time_limit(0);
。 - Pedro Lobitophp -d max_execution_time=1 -r 'while(true){$r=1*1;}'
或类似命令来观察,就会发现 CLI 并没有一个神奇的“永远无限制”的标志)。 - Wrikkenset_time_limit(0)
。 - Viktor Joras