Symfony3 Command - pcntl doesn't works

强颜欢笑 提交于 2019-12-12 23:43:44

问题


I want to stop executing my command from controller action so I tried to use pcntl to achieve this.

This is my code(Command):

protected $should_stop = false;

protected function execute(InputInterface $input, OutputInterface $output)
{
    pcntl_signal(SIGHUP, [$this, 'stopCommand']);

    foreach($something as $row) {
       pcntl_signal_dispatch();

       if($this->should_stop === true) {
          break;
       }
       ...
    }
}

protected function stopCommand()
{
    $this->should_stop = true;
}

But when I run my command it display error:

  [Symfony\Component\Debug\Exception\UndefinedFunctionException]                   
  Attempted to call function "pcntl_signal" from namespace "AppBundle\Command".

I have no idea how to fix it, could you guys help? Also if you have any other good method how to stop executing symfony command from the controller action it would be nice if you could post the solution here.


回答1:


I reinstalled XAMPP on my mac, here is php -m:

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imap
json
ldap
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

Now it's run in console without error, however when I run this command from my controller it display the same errors as before.



来源:https://stackoverflow.com/questions/47941237/symfony3-command-pcntl-doesnt-works

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!