nginx - php pthreads apache cannot load 问题(windows)
本机配置:
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 扩展 正常添加了

热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

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

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP用于构建动态网站,其核心功能包括:1.生成动态内容,通过与数据库对接实时生成网页;2.处理用户交互和表单提交,验证输入并响应操作;3.管理会话和用户认证,提供个性化体验;4.优化性能和遵循最佳实践,提升网站效率和安全性。

PHP和Python各有优劣,选择取决于项目需求和个人偏好。1.PHP适合快速开发和维护大型Web应用。2.Python在数据科学和机器学习领域占据主导地位。

PHP在数据库操作和服务器端逻辑处理中使用MySQLi和PDO扩展进行数据库交互,并通过会话管理等功能处理服务器端逻辑。1)使用MySQLi或PDO连接数据库,执行SQL查询。2)通过会话管理等功能处理HTTP请求和用户状态。3)使用事务确保数据库操作的原子性。4)防止SQL注入,使用异常处理和关闭连接来调试。5)通过索引和缓存优化性能,编写可读性高的代码并进行错误处理。

PHP主要是过程式编程,但也支持面向对象编程(OOP);Python支持多种范式,包括OOP、函数式和过程式编程。PHP适合web开发,Python适用于多种应用,如数据分析和机器学习。

可以通过以下步骤查询 Docker 容器名称:列出所有容器(docker ps)。筛选容器列表(使用 grep 命令)。获取容器名称(位于 "NAMES" 列中)。

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

PHP适合网页开发和快速原型开发,Python适用于数据科学和机器学习。1.PHP用于动态网页开发,语法简单,适合快速开发。2.Python语法简洁,适用于多领域,库生态系统强大。

PHP的核心优势包括易于学习、强大的web开发支持、丰富的库和框架、高性能和可扩展性、跨平台兼容性以及成本效益高。1)易于学习和使用,适合初学者;2)与web服务器集成好,支持多种数据库;3)拥有如Laravel等强大框架;4)通过优化可实现高性能;5)支持多种操作系统;6)开源,降低开发成本。
