使用cURL从PHP触发页面上脚本的最快方法,不要等待响应 [英] Fastest way to trigger a script on a page from PHP using cURL, don't wait for a response

查看:105
本文介绍了使用cURL从PHP触发页面上脚本的最快方法,不要等待响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用cURL和类似的东西:

Right now I am using cURL and something like that:

foreach ($urls as $url) {

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url ); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_exec($ch);

}

触发远程服务器上的php脚本。

to trigger a php script on a remote server.

我的事情是我只想触发该脚本,根本不在乎它返回的内容,而是想触发循环中的另一个地址。

My thing is I just want to trigger that script and doesn't care at all what it returns and I want to trigger another address that is in my loop.

因此,如何消除等待响应并仅触发服务器上的脚本(数组中有大约200个URL,我需要循环遍历并触发这些URL中的每个URL)

So, how can I eliminate waiting for the response and just trigger the scripts on the servers (I have about 200 urls in my array I need to loop through and trigger each of these urls).

因此,基本上,我只想触发脚本并移至下一个脚本,而不管它返回的内容。

So, basically I want just to trigger the script and move to the next one and don't care what it returns.

我的另一个担心是,如果我可以像这样将 curl_init()移到循环外:

And another concern of mine is that if I can move the curl_init() outside of the loop like that:

$ch = curl_init(); 

foreach ($urls as $url) {

    curl_setopt($ch, CURLOPT_URL, $url ); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_exec($ch);

}

如果有更快的方法来实现无需使用cURL,请告诉我。
我只需要从一个文件内的一个循环触发远程服务器上的100个脚本。

推荐答案

<?php
$fp = fsockopen("mesela.dom", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: mesela.dom\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    fclose($fp);
}
?>

这篇关于使用cURL从PHP触发页面上脚本的最快方法,不要等待响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆