【问题标题】:Php Class 'Thread' not found未找到 PHP 类“线程”
【发布时间】:2017-07-15 05:20:51
【问题描述】:

我已经通过以下http://php.net/manual/en/pthreads.installation.php 安装了 pthreads 从 http://windows.php.net/downloads/pecl/releases/pthreads/

我的 php 信息:- phpinfo();

PHP 版本 5.6.30 编译器:MSVC11 (Visual C++ 2012) 架构:x86 线程安全:启用

但错误仍然存​​在..

php -m 输出#

php -m PHP 警告:PHP 启动:pthreads:无法编译模块 使用模块 API=20121212 使用模块 API=20131226 编译的 PHP 这些 选项需要在第 0 行的未知中匹配警告:PHP 启动: pthreads:无法初始化使用模块 API=20121212 PHP 编译的模块 使用模块 API=20131226 编译这些选项需要在 第 0 行未知 [PHP 模块] bcmath bz2 calendar Core ctype curl date dom ereg exif fileinfo filter ftp gd gettext hash iconv json libxml mbstring mcrypt mhash mysql mysqli mysqlnd odbc

【问题讨论】:

  • 您确定,您已将extension=php_pthreads.dll 添加到正确的php.ini 中吗?
  • 你的php -m 输出是什么?
  • Thread Safety: enabled 与 pthreads 扩展无关。
  • 是的,我已经正确添加了 extension=php_pthreads.dll..
  • 这里是 php -m output# php -m PHP Warning: PHP Startup: pthreads: Unable t Module compiled with module API=20121212 PHP compiled with module API=20131226 这些选项需要在 Unknown 上匹配第 0 行警告:PHP 启动:pthreads:无法 ini 使用模块 API=20121212 编译的模块 PHP 使用模块 API=20131226 编译的这些选项需要在第 0 行 [PHP 模块] bcmath bz2 calendar Core ctype curl date dom ereg exif 中的 Unknown 中匹配fileinfo filter ftp gd gettext hash iconv json libxml mbstring mcrypt mhash mysql mysqli mysqlnd odbc

标签: php pthreads


【解决方案1】:

pthreads 对于 web 服务器环境是不安全的 (source) :-

我没有在 web 服务器环境中禁用 pthread 来惹恼你;一世 这样做是为了确保您的安全,并且不会推翻该决定。

PHP 和 Apache 不提供使其正常运行所需的 API 安全。

如果我明天修补 Apache 和 PHP 以包含一些额外的钩子 为了使其适当安全,您将永远无法做到 它可以扩展。

线程不是 Apache worker mpm 服务器的实用程序,它们是 软件架构的一部分;进来和开始 该架构中的其他线程是鲁莽的并破坏 该架构按原样扩展和运行的能力 有意的。

在 Apache 中使用 pthread 毫无意义,我让它继续工作 在以前的版本中,试图降低进入门槛 (每个人都对 Web 服务器感到满意)。那是一个错误,我的 错误;线程并不简单,当您尝试制作某些东西时 本来就很复杂很简单,你只会让它变得愚蠢。

允许在 Apache 内部启动线程,但无法启动 让 PHP 或 Apache 正确了解架构的变化 很粗鲁,而且非常愚蠢。

另一个注意事项,apache2 默认以 mpm_prefork 模式运行,这意味着 - 可以这么说 - “嘿 apache2,请为我分叉多个子进程,但每个子进程都有 一个线程

【讨论】:

    【解决方案2】:

    虽然Hassan Ahmed 的回复解释了为什么不应在 Web 服务器环境中使用 pthread,但这并不是您收到错误的原因。

    问题是您下载的 pthreads 二进制文件不是为您使用的 PHP 版本构建的。这会导致 pthread 的二进制 API 与其集成的 PHP 模块 API 不匹配。从您的 PHP 版本来看,您应该使用 2.0.10 版本的 pthreads,因为那是 PHP 5.6 版本的最后一个稳定版本。

    请注意,不再维护对 PHP 5.x 版本的 pthread 的支持。如果您想要最新的错误修复和功能,请使用 PHP 7.x 和 pthreads v3。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-03
      • 2012-08-07
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 2014-05-19
      • 1970-01-01
      相关资源
      最近更新 更多