Forum archive
Parallel Multithreaded Processing with CURL Lamp or similar V 15
I have written a PHP task/job scheduler... it fires off jobs which are PHP scripts that perform various tasks.
Currently its working pretty well, but every now and again I find that some of the jobs are "stuck" as another is currently running holding them up.
I had attempted to not allow this to happen via using the following to launch these jobs... this is from the terminal I am testing this and I use the PHP "exec()" command to fire within my code.
bash -c "exec nohup setsid curl -s 'http://localhost/MYJOBHERE_1.PHP' > /dev/null 2>&1 &"
When I have multiple to run I am just sending the same as above but adding another ampersand --> & to the beginning of the string so it becomes one long command like so:
bash -c "exec nohup setsid curl -s 'http://localhost/MYJOBHERE_1.PHP' > /dev/null 2>&1 &" & bash -c "exec nohup setsid curl -s 'http://localhost/MYJOBHERE_2.PHP' > /dev/null 2>&1 &" & bash -c "exec nohup setsid curl -s 'http://localhost/MYJOBHERE_3.PHP' > /dev/null 2>&1 &"
Now if I send like a bunch of these on the terminal that call scripts that write to a DB table so I can watch the time stamps... it seems like they all run, but at very different times... is this the operating system deciding to prioritize them or what? Is there any way to make sure they all run at the same time without causing other processes to slow them down?
The biggest issue is that some tasks are really of higher priority than others... is there a way for me to assign a priority to those tasks using the method I have?
Thanks for any an all input.
Thank you Jeremy for your detailed response. You never need to apologize for sharing great information as you do.
Let me explain a little more.
I agree that calling PHP directly from the command line would be better... but I am unable to in this instance as the PHP code I am calling does not work when I do. I will look further into why this is the case as I agree it would be much cleaner like that. The code I am using was generated by Scriptcase a RAD tool for database development and I suspect it doesnt run from the command line due to dependencies of some kind.
Since I am in fact using the webserver (apache) to handle these long running tasks... perhaps it is apache itself that is prioritizing and handling them in its own order?
My test environment has 2 PHP scripts that I can call with variables that tell them how long to run so I can test various lengths. If I run that command I listed above about 10 times in rapid succession (press up arrow, press enter, reapeat) then my command prompt is still available to me... so they are in fact backgrounded as I requested... but when I watch the tasks run it takes several minutes for it to run through them all... and they dont run in the order I started them either.
Perhaps, again, its apache handling all these processes as it wants to.
If I can get these .PHP programs to run from the command line, Ill be elminiating apache from the mix so Ill start there.
Thank you again!