Running command line PHP through PHP-FPM
Asked Answered
I

2

9

Currently I use PHP-FPM with NGINX for front end requests but also run some background processes through a long running PHP script using exec to run other scripts with the command line PHP. What I'm thinking though is that this would be more efficient if these were also run through PHP-FPM? Any ideas on how I would do this? Thanks.

Itinerancy answered 6/9, 2011 at 3:13 Comment(2)
I'm interested for other reasons; I'd like to be able to flush the APC cache from the command line, but this uses a different cache than for the PHP-FPM processed. If I can pipe a command to the FPM processes to execute, then the problem is solved.Chrisom
@ElYobo, what about creating a new vhost - "localhost", and make some scripts available there? :) It's not a good way, but most of the people get quite quickly what you're doing.Induction
C
9

FPM is a tool to Manage FastCGI Processes. Just shuffle the letters. While it manages long-running PHP processes, it does so only under the mental umbrella of FastCGI.

Because you're creating a background work queue, you want something designed to manage a background work queue and running processes.

Gearman is an excellent choice for the work queue half. It's platform and language agnostic, and scan scale to the heavens and back. The PECL extension works well.

For keeping those long-running processes going, take a look at Supervisor.

The two make a great duo. Check out this blog post by PHP hacker Matthew Weier O'Phinney that documents some of his exploration with Gearman and Supervisor.

Crinoline answered 6/9, 2011 at 5:6 Comment(2)
Link is outdated .... is it this? mwop.net/blog/240-Writing-Gearman-Workers-in-PHP.htmlInduction
Indeed, that's the one. Updated my post.Crinoline
H
4

Very late to this question (4 years) but the correct answer is cgi-fcgi which will let you pass commands and execute code in the already-in-memory php-fpm

Hireling answered 6/8, 2015 at 14:1 Comment(1)
Yep, I think this is what I was looking for way back then, thanks!Itinerancy

© 2022 - 2024 — McMap. All rights reserved.