使用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);
}
?>