Link to home
Start Free TrialLog in
Avatar of drupal_100
drupal_100Flag 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.
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

So what is the question?
ASKER CERTIFIED SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of drupal_100

ASKER

$pid = pcntl_fork();
fork process to scale up.
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
You need to explain better.
My recommendation: Split points:
http:#a40435577 (gheist) - 400 points
http:#a40483528 (gr8gonzo) - 100 points
I think both ways is acceptable like 50/50 I move threads out of process while you emphasize on hardships of thread programming.