{"id":229,"title":"php\u591a\u7ebf\u7a0b\u4f8b\u5b50","good":0,"bad":0,"hit":2329,"created_at":"2016-05-12 19:19:26","content":"

\u5982\u679c\u7528 MySQL \u6570\u636e\u5e93\uff0c\u4e00\u6761\u8054\u5408\u67e5\u8be2\u7684SQL\uff0c\u4e5f\u8bb8\u5c31\u53ef\u4ee5\u5904\u7406\u5b8c\u4e1a\u52a1\u903b\u8f91\uff0c\u4f46\u662f\uff0c\u9047\u5230\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\uff0c\u5c31\u6b47\u83dc\u4e86\u3002\u5982\u679c\u7528 NoSQL \r\n\u6570\u636e\u5e93\uff0c\u4e5f\u8bb8\u9700\u8981\u5341\u6b21\u67e5\u8be2\uff0c\u624d\u80fd\u5904\u7406\u5b8c\u540c\u6837\u5730\u4e1a\u52a1\u903b\u8f91\uff0c\u4f46\u6bcf\u6b21\u67e5\u8be2\u90fd\u6bd4 MySQL \r\n\u8981\u5feb\uff0c\u5341\u6b21\u5faa\u73afNoSQL\u67e5\u8be2\u4e5f\u8bb8\u6bd4\u4e00\u6b21MySQL\u8054\u5408\u67e5\u8be2\u66f4\u5feb\uff0c\u5e94\u5bf9\u51e0\u4e07\u6b21\/\u79d2\u7684\u67e5\u8be2\u5b8c\u5168\u6ca1\u95ee\u9898\u3002\u5982\u679c\u52a0\u4e0aPHP\u591a\u7ebf\u7a0b\uff0c\u901a\u8fc7\u5341\u4e2a\u7ebf\u7a0b\u540c\u65f6\u67e5\u8be2\r\nNoSQL\uff0c\u8fd4\u56de\u7ed3\u679c\u6c47\u603b\u8f93\u51fa\uff0c\u901f\u5ea6\u5c31\u8981\u66f4\u5feb\u4e86\u3002\u6211\u4eec\u5b9e\u9645\u7684APP\u4ea7\u54c1\u4e2d\uff0c\u8c03\u7528\u4e00\u4e2a\u901a\u8fc7\u7528\u6237\u559c\u597d\u5b9e\u65f6\u63a8\u8350\u5546\u54c1\u7684PHP\u63a5\u53e3\uff0cPHP\u9700\u8981\u5bf9BigSea \r\nNoSQL\u6570\u636e\u5e93\u53d1\u8d77500~1000\u6b21\u67e5\u8be2\uff0c\u6765\u5b9e\u65f6\u7b97\u51fa\u7528\u6237\u7684\u4e2a\u6027\u559c\u597d\u5546\u54c1\u6570\u636e\uff0cPHP\u591a\u7ebf\u7a0b\u7684\u4f5c\u7528\u975e\u5e38\u660e\u663e\u3002<\/p>

<\/p>

\u672c\u4eba\u4f7f\u7528\u73af\u5883win10 64\u4f4d\u7cfb\u7edf\uff0cwamp2.5(php5.5.12)<\/p>

\u4e00\u3001\u4e0b\u8f7dpthreads\u6269\u5c55\u4e0b\u8f7d\u5730\u5740\uff1ahttp:\/\/windows.php.net\/downloads\/pecl\/releases\/pthreads\u6839\u636e\u672c\u4eba\u73af\u5883\uff0c\u6211\u4e0b\u8f7d\u7684\u662fhttp:\/\/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\u30025.5\u4ee3\u8868php\u7684\u7248\u672c\u3002ts\u8868\u793aphp\u8981\u7ebf\u7a0b\u5b89\u5168\u7248\u672c\u7684\u3002vc11\u8868\u793aphp\u8981Visual C++ \u7f16\u8bd1\u5668\u7f16\u8bd1\u7684\u7248\u672c\u3002x86\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>"}