run php script within php

Silver-0-surfer

Well-Known Member
Joined
Jan 5, 2008
Messages
317
Reaction score
7
Location
CPT
Hi

I created a script thats connecting to a server on a socket. It runs on an infinite loop.

I need to be able to initiate this script from with a php page. Normally I would run it in on linux like this:

php infinitescrip.php &

to have it running in the background, but how can I do this within php.

if I add like

echo `php infinitescrip.php &`;

the page just hangs, I'm assuming that it not sending it to a background proccess, does anyone know if this can be done?
 
I tried everything on that site but got nothing to work.

ended up creating a bash script to call the php file and then calling the bash from the web, works fine.
 
I used to launch a Headless Virtualbox session from the command line but the problem was it kept the shell open and as soon as you close it it closes the Vbox PID aswell.

Or when you terminate the vbox session it would return to the next line in the shell.



I then found a command that runs a command but then ends the command shell keeping the command running without terminating it as well.



Look at http://linux.101hacks.com/unix/nohup-command/





The command is called nohup so i'm sure it will resolve your problem.



I think you will need to dosomething like this on your webpage.



<?php



system ("nohup php /var/www/infinitescrip.php");



?>
 
Check out "semaphore"

I used it to initiate a "background" script to process some data as the user need to not only get progress of the request, but if the request was delayed it would not cause the browser to hang. What makes it even better is the load balancing PHP handles for semaphore. In my case I could only have 10 instances running and the rest needed to be queued.
 
Top
Sign up to the MyBroadband newsletter
X