[英]pthreads with phalcon 3.3 - PHP Fatal error
I am new to Phalcon and Pthreads. 我是Phalcon和Pthreads的新手。
My environment is as follows: 我的环境如下:
$ php -v PHP 7.2.2 (cli) (built: Feb 19 2018 10:04:19) ( ZTS DEBUG ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.2, Copyright (c) 1999-2018, by Zend Technologies $ php -v PHP 7.2.2(cli)(内置:2018年2月19日10:04:19)(ZTS DEBUG)版权所有(c)1997-2018 The PHP Group Zend Engine v3.2.0,版权所有(c)1998-2018 Zend Technologies with Zend OPcache v7.2.2,版权所有(c)1999-2018,Zend Technologies
$ php -m | $ php -m | grep pthreads pthreads
grep pthreads pthreads
phpinfo() says the following: phpinfo()表示以下内容:
PHP Version 7.0.25-0ubuntu0.16.04.1 PHP版本7.0.25-0ubuntu0.16.04.1
Thread Safety disabled 线程安全禁用
Despite compilation with --enable-maintainer-zts \\ --with-tsrm-pthreads 尽管使用--enable-maintainer-zts \\ --with-tsrm-pthreads进行编译
I followed these instructions: https://blog.programster.org/ubuntu16-04-compile-php-7-2-with-pthreads 我按照以下说明进行操作: https : //blog.programster.org/ubuntu16-04-compile-php-7-2-with-pthreads
I have two pieces of code in the same folder: 我在同一文件夹中有两段代码:
class Task extends Threaded
{
private $value;
public function __construct(int $i){
$this->value = $i;
}
public function run(){
$s=0;
$rand = rand(1, 100);
$sleep = rand(1, 500);
for ($i=0; $i<$rand; $i++){
$s++;
time_nanosleep (0, $sleep);
}
echo "Task: {$this->value}\n";
}
}
# Create a pool of $n threads
$n = 16;
$pool = new Pool($n);
for ($i = 0; $i < 1000; ++$i){
$pool->submit(new Task($i));
}
while ($pool->collect());
$pool->shutdown();
This code runs perfectly. 此代码运行完美。
My other piece of code is instantiated from phalcon. 我的另一段代码是从phalcon实例化的。
<?php
class MultiapiPool
{
private $providers;
private $dependencies;
private $input;
public function __construct($p, $d, $i){
$this->providers = $p;
$this->dependencies = $d;
$this->input = $i;
}
private function getProviders(){
return $this->providers;
}
private function getDependencies(){
return $this->dependencies;
}
private function getInput(){
return $this->input;
}
public function run(){
$providers = $this->getProviders();
$pool = new Pool(count($providers));
return array(
'input' =>$this->getInput(),
'dependencies'=>$this->getDependencies(),
'providers'=>$providers);
}
}
This class throws an error: 此类引发错误:
PHP Fatal error: Uncaught Error: Class 'Pool' not found in /var/www/html/tutorial/app/libraries/MultiapiPool.php:29 PHP致命错误:未捕获的错误:在/var/www/html/tutorial/app/libraries/MultiapiPool.php:29中找不到类“ Pool”
The offending line is: $pool = new Pool(count($providers)); 令人讨厌的行是:$ pool = new Pool(count($ providers));
My questions are: 我的问题是:
How new Pool() works in one file but not in another? new Pool()如何在一个文件中起作用而在另一个文件中却不起作用? There are no special includes in the working file.
工作文件中没有特殊内容。
Thread Safety disabled 线程安全禁用
Despite compilation with --enable-maintainer-zts \\ --with-tsrm-pthreads 尽管使用--enable-maintainer-zts \\ --with-tsrm-pthreads进行编译
Your class that works is extending Threaded: 您可以使用的课程正在扩展Threaded:
class Task extends Threaded
Your class that doesn't work is not extending Threaded: 您无法使用的课程无法扩展Threaded:
class MultiapiPool
Try to extend MultiapiPool to use Threaded and see if that fixes things: 尝试扩展MultiapiPool以使用Threaded,看看是否可以解决问题:
class MultiapiPool extends Threaded
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.