本机配置:
apache:2.2-x86
php:5.4 ts-x86
系统:windows 64
pthreads 配置
下载地址:http://windows.php.net/downloads/pecl/releases/pthreads/2.0.9/
pthreads 5.4 下两个文件:
php_pthreas.dll 和 pthreadVC2.dll
php_pthreas.dll 放入php ext文件中
pthreadVC2.dll 放入php 根目录
php.ini
extension=php_pthreads.dll
apache http.conf 配置
LoadFile "D:/wamp/php/pthreadVC2.dll"
然后重启apache 无法启动 cmd 进入apache/bin 命令 httpd -k start 报 cannot load pthreadVC2.dll
疑问:
是否是php版本要64位 apache 才能调用 pthreadVC2.dll?
测试代码:
<code><?php class AsyncOperation extends Thread { public function __construct($arg){ $this->arg = $arg; } public function run(){ if($this->arg){ printf("Hello %s\n", $this->arg); } } } $thread = new AsyncOperation("World"); if($thread->start()) $thread->join(); ?></code>
通过apache 不加载 pthreadVC2.dll ,直接能打印出 helloword
nginx:
运行测试代码 毫无结果
提问:
php pthreads 多线程扩展 nginx 如何配置?
回复内容:
本机配置:
apache:2.2-x86
php:5.4 ts-x86
系统:windows 64
pthreads 配置
下载地址:http://windows.php.net/downloads/pecl/releases/pthreads/2.0.9/
pthreads 5.4 下两个文件:
php_pthreas.dll 和 pthreadVC2.dll
php_pthreas.dll 放入php ext文件中
pthreadVC2.dll 放入php 根目录
php.ini
extension=php_pthreads.dll
apache http.conf 配置
LoadFile "D:/wamp/php/pthreadVC2.dll"
然后重启apache 无法启动 cmd 进入apache/bin 命令 httpd -k start 报 cannot load pthreadVC2.dll
疑问:
是否是php版本要64位 apache 才能调用 pthreadVC2.dll?
测试代码:
<code><?php class AsyncOperation extends Thread { public function __construct($arg){ $this->arg = $arg; } public function run(){ if($this->arg){ printf("Hello %s\n", $this->arg); } } } $thread = new AsyncOperation("World"); if($thread->start()) $thread->join(); ?></code>
通过apache 不加载 pthreadVC2.dll ,直接能打印出 helloword
nginx:
运行测试代码 毫无结果
提问:
php pthreads 多线程扩展 nginx 如何配置?
个人觉得pthreads这个扩展不适合应用在Apache/PHP-FPM这些Web服务上,因为这些服务本身就有自己的进程管理模型.在CLI下使用pthreads可能更好些.还有,需要注意的是,不要在线程里使用echo输出内容,否则会出现不可预知的错误和行为,比如乱码(garbled).尤其是在非CLI环境下,比如Apache/PHP-FPM.另外,我在Ubuntu上用Nginx+PHP-FPM跑下面的多线程程序,是能正常运行的:
<code><?php header('Content-Type: text/html; charset=utf-8'); ob_start(); function do_flush() { echo '<br />'.str_repeat(' ', 1024*4); ob_flush(); flush(); } class Request extends Thread { public $url; public $data; public function __construct($url) { $this->url = $url; } public function run() { // 线程处理一个耗时5秒的任务 for($i=0;$iurl); $response = $this->url; if ($response) { $this->data = array($response); } //echo "线程: 任务完成<br>"; } } $request = new Request('hello.html'); // 运行线程:start()方法会触发run()运行 if ($request->start()) { // 主进程处理一个耗时10秒的任务,此时线程已经工作 for($i=0;$ijoin(); echo '线程返回数据: '.$request->data[0]; ob_end_flush();</code>
加载pthreads插件必须要求php是 ZTS Enabled ( Thread Safety ) 版,请自行检查相关版本
我将环境整体换了一下 apache2.4 php 5.6 ts-x64 threads 扩展 正常添加了

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

记事本++7.3.1
好用且免费的代码编辑器

Atom编辑器mac版下载
最流行的的开源编辑器