日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php多线程安装pthreads步骤详解

發布時間:2024/9/20 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php多线程安装pthreads步骤详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

摘要: 本文講的是php多線程安裝pthreads步驟詳解, PHP擴展下載:https://github.com/krakjoe/pthreads PHP手冊文檔:http://php.net/manual/zh/book.pthreads.php 安裝腳本 ?代碼如下 復制代碼

PHP擴展下載:https://github.com/krakjoe/pthreads
PHP手冊文檔:http://php.net/manual/zh/book.pthreads.php
安裝腳本

?代碼如下復制代碼
#!/bin/sh
cd /web/soft/php
if [ -d "pthreads-master" ];then
rm -rf pthreads-master
fi
unzip pthreads-master.zip
cd pthreads-master
/web/server/php/bin/phpize
./configure --with-php-config=/web/server/php/bin/php-config
make
make install
rm -rf pthreads-master
PHPINI="/web/server/php/etc/php.ini"
sed -i '907a extension = "pthreads.so"' $PHPINI
#更新php-fpm配置
sed -i 's%;pid = run/php-fpm.pid%pid = run/php-fpm.pid%' /web/server/php/etc/php-fpm.conf
sed -i 's%;error_log = log/php-fpm.log%error_log = log/php-fpm.log%' /web/server/php/etc/php-fpm.conf
#殺死php-fpm進程
ps aux | grep "php" | grep -v "grep" | awk '{print $2}' | xargs -i kill -9 {}
#啟動php-fpm
/web/server/php/sbin/php-fpm
在安裝過程中出現錯誤
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers

解決方法是安裝或升級re2c 0.13.4以上版本。
下面我們用rpm包安裝此庫。
centos-5 32位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el5.rf.i386.rpm
centos-5 64位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el5.rf.x86_64.rpm
centos-6 32位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.i686.rpm
centos-6 64位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.x86_64.rpm
configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled
原因: 我在編譯php的時候沒有加入 --enable-maintainer-zts ,這個必須要重新編譯php,不能動態加載的!
于是我重新編譯了php,在原來的編譯參數基礎上那個加入了 --enable-maintainer-zts ,重新編譯安裝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();
}
foreach ($thread_array as $thread_array_key => $thread_array_value)
{
while($thread_array[$thread_array_key]->isRunning())
{
usleep(10);
}
if($thread_array[$thread_array_key]->join())
{
$variable_data[$thread_array_key] = $thread_array[$thread_array_key]->data;
}
}
return $variable_data;
}
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);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
for ($i=0; $i < 100; $i++)
{
$urls_array[] = array("name" => "baidu", "url" => "http://www.111cn.net/ s?wd=".mt_rand(10000,20000));
}
$t = microtime(true);
$result = model_thread_result_get($urls_array);
$e = microtime(true);
echo "多線程:".($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循環:".($e-$t)."\n";
?>

以上是云棲社區小編為您精心準備的的內容,在云棲社區的博客、問答、公眾號、人物、課程等欄目也有的相關內容,歡迎繼續使用右上角搜索按鈕進行搜索php , 編譯 , 多線程 代碼 php 多線程 pthreads、php pthreads、pthreads php擴展、php pthreads 安裝、php7 pthreads,以便于您獲取更多的相關知識。

來源:https://yq.aliyun.com/ziliao/8836

總結

以上是生活随笔為你收集整理的php多线程安装pthreads步骤详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。