Avatar of drupal_100
drupal_100
Flag for United States of America asked on

Run PHP script as daemon and auto scale

Run PHP script as daemon and auto scale

Have a PHP program to process events stored in database,
event table
id      description
1      event 1
2       event 2
3      event 3
...

process_event.php
<?php
do loop {
get an event from table
process the event
remove the event from table
}
?>

Want to run PHP program as daemon.
process_event.sh
#!/bin/bash
nice php process_event.php
 
Here it only runs a single worker.
Want to auto scale additional workers when needed.
For example, when table has 10 events, run 1 worker,
when table has 20 events, run 2 workers,
and automatically scale to run more or less workers according to number of events.
PHPLinux

Avatar of undefined
Last Comment
gheist

8/22/2022 - Mon
gr8gonzo

So what is the question?
ASKER CERTIFIED SOLUTION
gheist

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
drupal_100

ASKER
$pid = pcntl_fork();
fork process to scale up.
drupal_100

ASKER
I've requested that this question be closed as follows:

Accepted answer: 0 points for drupal_100's comment #a40483418

for the following reason:

Get answer
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gheist

Your request does not concern programming, or manually forking process where you should be using a thread.

Both PHP-FPM and apache mod_fcgi exactly scales dynamically (untill 1024 parallel requests without tuning, that yields 20x that in users of site using it)
gheist

You need to explain better.
gr8gonzo

My recommendation: Split points:
http:#a40435577 (gheist) - 400 points
http:#a40483528 (gr8gonzo) - 100 points
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gheist

I think both ways is acceptable like 50/50 I move threads out of process while you emphasize on hardships of thread programming.