简体   繁体   English

PHP:了解CURL超时

[英]PHP : understand the CURL timeout

From a php page, i have to do a get to another php file. 从一个php页面,我必须获取另一个php文件。 I don't care to wait for the response of the get or know whether it is successful or not. 我不在乎等待get的响应,也不知道它是否成功。

The file called could end the script also in 5-6 seconds, so i don't know how to handle the get timeout considering what has been said before. 调用的文件也可能在5-6秒内结束脚本,因此考虑到之前所说的内容,我不知道如何处理获取超时。

The code is this 代码是这个

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mywebsite/myfile.php'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$content = trim(curl_exec($ch));
curl_close($ch);

对于第一个任务(不需要等待响应的地方),您可以启动新的后台进程,然后在该进程下面编写代码,该代码将在另一个页面上重定向您。

Yeah, you definitely shouldn't be creating a file on the server in response to a GET request. 是的,您绝对不应该在服务器上创建文件以响应GET请求。 Even as a side-effect, it's less than ideal; 即使有副作用,也不如理想。 as the main purpose of the request, it just doesn't make sense. 作为请求的主要目的,这没有任何意义。

If you were doing this as a POST, you'd still have the same issue to work with, however. 如果这样做,作为一个POST,你仍旧有同样的问题一起工作,但是。 In that case, if the action can't be guaranteed to happen quickly enough to be acceptable in the context of HTTP, you'll need to hive it off somewhere else. 在那种情况下,如果不能保证动作足够快地发生以至于在HTTP上下文中可以接受,那么您就需要将其移开。 Eg make your HTTP request send a message to some other system which then works in parallel whilst the HTTP response is free to be sent back immediately. 例如,使您的HTTP请求向其他系统发送消息,然后该系统并行工作,同时HTTP响应可以立即免费发送回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM