PHP异步调用多线程
Posted Rakishly
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP异步调用多线程相关的知识,希望对你有一定的参考价值。
$data["name"] = ‘godlike‘;
$data["age"] = 18;
$post = http_build_query($data);
$len = strlen($post);
$host = "www.example.com";
$path = "/member/lackGoods/sendSmsAll";
$errno =‘‘;
$errstr=‘‘;
$fp = fsockopen($host,80,$errno,$errstr,30);
if (!$fp) {
echo "$errstr ($errno)\n";
} else {
$out = "POST $path HTTP/1.1\r\n"; //通过POST方式
$out .= "Host: $host\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: $len\r\n";
$out .= "\r\n";
$out .= $post . "\r\n";
fwrite($fp, $out);
// while (!feof($fp)) {
// $receive .= fgets($fp, 128);
// }
fclose($fp);
}
public function sendSmsAll()
{
var_dump($_POST);
//发送短信的方法
}
//还可以使用curl实现
$ch = curl_init();
$curl_opt = array(CURLOPT_URL, ‘http://www.example.com/backend.php‘,
CURLOPT_RETURNTRANSFER, 1,
CURLOPT_TIMEOUT, 1,);
curl_setopt_array($ch, $curl_opt);
curl_exec($ch);
curl_close($ch);
以上是关于PHP异步调用多线程的主要内容,如果未能解决你的问题,请参考以下文章
异步和多线程,委托异步调用,Thread,ThreadPool,Task,Parallel,CancellationTokenSource