Jump to content

PHP running a script in the background

Yemto

So I been attempting this a while now, at work we have a php script which acts like a server. I'm the only one that knows how to start it up, and that leads to me getting phone calls when I'm off work, when the script have stopped. Usually it's when someone restarts the computer. So I want to make an easy start button which can be used to start the script again. But the problem is that the webpage hangs/freezes when the button is clicked, witch is something I don't want.

 

Here is what I start the script with.

shell_exec("php -f \"".__DIR__."/start.php\" > out.log &");

I have tried with a few different commands, and functions. (exec, system, shell_exec, passthru) but all of them freezes the page, does anyone know a solution? Oh, and it have to run on both windows and linux. 

Link to comment
Share on other sites

Link to post
Share on other sites

Try calling the script with Ajax.

Link to comment
Share on other sites

Link to post
Share on other sites

Try calling the script with Ajax.

 

I have tried, it still freezes the page, even with the async set to true.

Link to comment
Share on other sites

Link to post
Share on other sites

I have tried, it still freezes the page, even with the async set to true.

what do you mean by "freezes"? that should only happen if there is a script blocking the browser, or if the server is flooding the client with a massive response

async requests shouldn't block anything

Link to comment
Share on other sites

Link to post
Share on other sites

PHP will only continue loading the page once the script is done running. So basically if your script is running something permanent, the page will wait permanently for the script to finish.

I still have the same issue. Unfortunately I don't know anything about AJAX so i wasn't able to fix it.

Hopefully this little ammount of info will help you along the way though :)

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×