http:\/\/windows.php.net\/downloads\/pecl\/releases\/pthreads\/2.0.9\/php_pthreads-2.0.9-5.5-ts-vc11-x64.zip<\/a>
<\/p>2.0.9\u4ee3\u8868pthreads\u7684\u7248\u672c\u3002
5.5\u4ee3\u8868php\u7684\u7248\u672c\u3002
ts\u8868\u793aphp\u8981\u7ebf\u7a0b\u5b89\u5168\u7248\u672c\u7684\u3002
vc11\u8868\u793aphp\u8981Visual C++ \u7f16\u8bd1\u5668\u7f16\u8bd1\u7684\u7248\u672c\u3002
x86\u5219\u8868\u793a32\u4f4d\u7684 x64\u8868\u793a64\u4f4d\uff0c<\/p>
\u600e\u4e48\u786e\u5b9a\u6700\u540e\u4e24\u9879\uff0c\u7528phpinfo()\u51fd\u6570\u67e5\u770b\u7cfb\u7edf\u4fe1\u606f\uff0c\u7ea2\u8272\u90a3\u4e24\u9879\u5c31\u662f\uff1a<\/p>
PHP Version 5.5.12<\/p>
System Windows NT LENOVO-PC 6.2 build 9200 (Windows 8 Business Edition) AMD64 <\/p>
Build Date Apr 30 2014 11:15:47 <\/p>
Compiler MSVC11<\/strong><\/span> (Visual C++ 2012) <\/p>Architecture x64 <\/span><\/strong><\/p>
<\/p>
\u4e8c\u3001\u5b89\u88c5pthreads\u6269\u5c55
\u590d\u5236php_pthreads.dll \u5230\u76ee\u5f55 binphpext \u4e0b\u9762\u3002\uff08\u672c\u4eba\u8def\u5f84D:wampbinphpphp5.5.12ext\uff09
\u590d\u5236pthreadVC2.dll \u5230\u76ee\u5f55 binphp \u4e0b\u9762\u3002\uff08\u672c\u4eba\u8def\u5f84D:wampbinphpphp5.5.11\uff09
\u590d\u5236pthreadVC2.dll \u5230\u76ee\u5f55 C:windowssystem32 \u4e0b\u9762\u3002
\u6253\u5f00php\u914d\u7f6e\u6587\u4ef6php.ini\u3002\u5728\u540e\u9762\u52a0\u4e0aextension=php_pthreads.dll
\r\n \u63d0\u793a\uff01Windows\u7cfb\u7edf\u9700\u8981\u5c06 pthreadVC2.dll \u6240\u5728\u8def\u5f84\u52a0\u5165\u5230 PATH \u73af\u5883\u53d8\u91cf\u4e2d\u3002\u6211\u7684\u7535\u8111--->\u9f20\u6807\u53f3\u952e--->\u5c5e\r\n\u6027--->\u9ad8\u7ea7--->\u73af\u5883\u53d8\u91cf--->\u7cfb\u7edf\u53d8\u91cf--->\u627e\u5230\u540d\u79f0\u4e3aPath\u7684--->\u7f16\u8f91--->\u5728\u53d8\u91cf\u503c\u6700\u540e\u9762\r\n\u52a0\u4e0apthreadVC2.dll\u7684\u5b8c\u6574\u8def\u5f84\uff08\u672c\u4eba\u7684\u4e3aC:WINDOWSsystem32pthreadVC2.dll\uff09\u3002
<\/p>
\u91cd\u542fapache<\/p>
<\/p>
\u4e09\u3001\u6d4b\u8bd5<\/p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\u591a\u7ebf\u7a0b\u4f8b\u5b50\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
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();
}
foreach ($thread_array as $thread_array_key => $thread_array_value)
{
while($thread_array[$thread_array_key]->isRunning())
{
usleep(10); \/\/\u4ee5\u6307\u5b9a\u7684\u5fae\u79d2\u6570\u5ef6\u8fdf\u6267\u884c,\u4f11\u606f10\u5fae\u79d2
}
if($thread_array[$thread_array_key]->join()) \/\/\u963b\u585e\u5f53\u524d\u7684\u7ebf\u7a0b\uff0c\u76f4\u5230\u53e6\u5916\u4e00\u4e2a\u7ebf\u7a0b\u8fd0\u884c\u7ed3\u675f
{
$variable_data[$thread_array_key] = $thread_array[$thread_array_key]->data;
}
}
return $variable_data;
}
\/\/\u6a21\u62df\u7528\u6d4f\u89c8\u5668\u53d1\u8d77\u8bf7\u6c42
function model_http_curl_get($url,$userAgent="")
{
$userAgent = $userAgent ? $userAgent : 'Mozilla\/4.0 (compatible; MSIE 7.0; Windows NT 5.2)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
\/\/CURLOPT_RETURNTRANSFER\u5c06 curl_exec()\u83b7\u53d6\u7684\u4fe1\u606f\u4ee5\u6587\u4ef6\u6d41\u7684\u5f62\u5f0f\u8fd4\u56de\uff0c\u800c\u4e0d\u662f
\/\/\u76f4\u63a5\u8f93\u51fa\u3002\u5982\u679c\u9009\u9879\u88ab\u8bbe\u7f6e\uff0c\u51fd\u6570\u6267\u884c\u6210\u529f\u65f6\u4f1a\u8fd4\u56de\u6267\u884c\u7684\u7ed3\u679c\uff0c\u5931\u8d25\u65f6\u8fd4\u56de FALSE
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5); \/\/\u8bbe\u7f6ecURL\u5141\u8bb8\u6267\u884c\u7684\u6700\u957f\u79d2\u6570
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
for ($i=0; $i < 100; $i++)
{ \/\/\u7ec4\u88c5\u4e00\u767e\u4e2a\u767e\u5ea6\u7684url\u641c\u7d22\u8bf7\u6c42\uff0cmt_rand\u6bd4rand\u4ea7\u751f\u968f\u673a\u6570\u7684\u901f\u5ea6\u5feb4\u500d
$urls_array[] = array("name" => "baidu", "url" => "http:\/\/www.baidu.com\/s?wd=".mt_rand(10000,20000));
}
\/\/microtime \u2014 \u8fd4\u56de\u5f53\u524d Unix \u65f6\u95f4\u6233\u548c\u5fae\u79d2\u6570,\u53c2\u6570\u4e3aTRUE\uff0c microtime() \u5c06\u8fd4\u56de\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002
\/\/echo microtime(true); \u8f93\u51fa\u7c7b\u4f3c\uff1a1463052528.9284
\/\/echo '<br\/>';
\/\/echo microtime(); \u8f93\u51fa\u7c7b\u4f3c\uff1a92837400 1463052528
$t=microtime(true);
$result = model_thread_result_get($urls_array);
$e = microtime(true);
echo "\u591a\u7ebf\u7a0b\uff1a".($e-$t)."n";
$t = microtime(true);
foreach ($urls_array as $key => $value)
{
$result_new[$key] = model_http_curl_get($value["url"]);
}
$e = microtime(true);
echo "For\u5faa\u73af\uff1a".($e-$t)."n";
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/end\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
<\/p>
\u8f93\u884c\u7ed3\u679c\uff1a<\/p>
\u591a\u7ebf\u7a0b\uff1a5.3671960830688\r\nFor\u5faa\u73af\uff1a10.585718154907<\/p>
\u4efb\u52a1\u8d8a\u591a\u7684\u65f6\u5019\uff0c\u4f18\u52bf\u8d8a\u660e\u663e\uff1b
<\/p>"}