以前使用curl的多線程並不是真正的多線程,只是一種模擬的多線程,現在使用pthreads來實現真正意義上的多線程。
下載:
windows下:
http://windows.php.net/downloads/pecl/releases/pthreads/0.0.45/
mac、unix、linux下:
https://github.com/krakjoe/pthreads
windows下:
解壓得到pthreadVC2.dll和php_pthreads.dll文件,把vc2文件放到php.exe同級目錄,把php_pthreads.dll放到擴展目錄下。
修改php.ini文件 添加extension=php_pthreads.dll
修改Apache配置文件httpd.conf 添加LoadFile "yourpath/php/pthreadVC2.dll"
mac、unix、linux下:
具體可參考宴哥的博客http://blog.s135.com/pthreads/
調用方式:
具體的用法也可以參考宴哥的博客http://blog.s135.com/pthreads/
結合以前的get_html也可以這樣來實現類
threads = '' = __construct(, = ->url = ->options = (!(-> ->data = ->get_html(->url, -> get_html(, = (( [CURLOPT_RETURNTRANSFER] = [CURLOPT_TIMEOUT] = 5 = curl_init( curl_setopt_array(, = curl_exec( curl_close( ( === }