0

I am attempting to use pthreads with Apache FPM.

Step 1.

After installing and recompiling php according to:

https://blog.programster.org/ubuntu16-04-compile-php-7-2-with-pthreads

The server works as expected and I can run pthreads from CLI.

Step 2.

Then I need to run threads from a web server so I followed the instructions from:

https://antrecu.com/blog/run-php7-fpm-apache-mpmevent-ubuntu-1604

After sudo service apache2 restart && sudo service php7.0-fpm restart:

Job for apache2.service failed because the control process exited with error code. 
See "systemctl status apache2.service" and "journalctl -xe" for details.

$ systemctl status apache2.service

apache2.service - LSB: Apache2 web server

   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)

  Drop-In: /lib/systemd/system/apache2.service.d

           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Mon 2018-03-12 17:09:45 PDT; 3min 35s ago

     Docs: man:systemd-sysv-generator(8)


  Process: 30818 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)

  Process: 32443 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)


Mar 12 17:09:45 ubuntu apache2[32443]:  * The apache2 configtest failed.

Mar 12 17:09:45 ubuntu apache2[32443]: Output of config test was:

Mar 12 17:09:45 ubuntu apache2[32443]: [Mon Mar 12 17:09:45.084452 2018] [:crit] [pid 32454:tid 139629110323072] 

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You n.. (output cut off in SSH client)

Mar 12 17:09:45 ubuntu apache2[32443]: AH00013: Pre-configuration failed

Mar 12 17:09:45 ubuntu apache2[32443]: Action 'configtest' failed.

Mar 12 17:09:45 ubuntu apache2[32443]: The Apache error log may have more information.

Mar 12 17:09:45 ubuntu systemd[1]: apache2.service: Control process exited, code=exited status=1

Mar 12 17:09:45 ubuntu systemd[1]: Failed to start LSB: Apache2 web server.

Mar 12 17:09:45 ubuntu systemd[1]: apache2.service: Unit entered failed state.

Needless to say I am a newbie when it comes to compiling Linux packages.

Any suggestions?

Nic3500
  • 8,144
  • 10
  • 29
  • 40
pigfox
  • 1,301
  • 3
  • 28
  • 52

1 Answers1

2

I am attempting to use pthreads with Apache FPM.

You can't. Find a way to work without them.

The pthreads extension cannot be used in a web server environment. Threading in PHP is therefore restricted to CLI-based applications only.

-- http://php.net/manual/en/intro.pthreads.php

  • Interesting, per this thread: https://stackoverflow.com/questions/49183807/parallel-asynchronous-php "It's not that pthreads is incompatible with apache, it's that it's incompatible with mod_php. Use use an FCGI worker model like FPM and you can use pthreads all you want." Do I misunderstand this? – pigfox Mar 13 '18 at 22:09
  • That answer is incorrect. The author of the PHP pthreads extension has explicitly said that ["you can't use pthreads safely and sensibly anywhere but CLI"](https://github.com/krakjoe/pthreads#sapi-support). FPM is not CLI. –  Mar 13 '18 at 22:11
  • It's also that multithreading in a webserver environment does not make sense at all. – Charlotte Dunois Mar 16 '18 at 12:58