namespace Service\Component\ThreadWebRequest;
use Thread;
class ThreadWebRequest extends Thread {
public $url;
public $headers;
public $data;
function __construct($url, $headers) {
$this->url = $url;
$this->headers = $headers;
//$this->start();
}
public function run() {
$timeout = 0; // set to zero for no timeout
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0"); //Optional
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // Avoid SSL certificate issue
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$file_contents = curl_exec($ch);
if(curl_errno($ch))
{
return 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
$this->data = $file_contents;
}
}
在我的控制器中我有这个,
$threadRequest = new ThreadWebRequest($value['uri'], $headers);
$threadRequest->start() && $threadRequest->join();
$batchResponse = $threadRequest->data;
我收到此错误。 PHP致命错误:在第300行的/opt/services-api/v2/vendor/composer/ClassLoader.php中的非对象上调用成员函数findFile()
如果我在苗条之外访问线程,它工作正常。不确定在slim框架路由器中启动线程需要做什么。