unzip pthreads-master.zip cd pthreads-master /Data/apps/php/bin/phpize ./configure --with-php-config=/Data/apps/php/bin/php-config make make install php.ini中添加: 复制代码 代码如下: vi /Data/apps/php/etc/php.ini extension = "pthreads.so" 给出一段PHP多线程、与For循环,抓取百度搜索页面的PHP代码示例: 复制代码 代码如下: ?php class test_thread_run extends Thread { public $url; public $data;
public function __construct($url) { $this- url = $url; }
public function run() { if(($url = $this- url)) { $this- data = model_http_curl_get($url); } } }
function model_thread_result_get($urls_array) { foreach ($urls_array as $key = $value) { $thread_array[$key] = new test_thread_run($value["url"]); $thread_array[$key]- start(); }