views:

88

answers:

2

Hello all,

I have two problems which are related.

1) I have a batch file that contains this:

net stop wampapache
net start wampapache

Which tries to stop and start my wamp server. When I double click the stop.bat file with the above it works successfully. When I try to run that from my PHP script, it stops the server but doesn't start it fully which I am guessing is because Apache is waiting for that PHP process to exit?

function php_kill(){

    exec('stop.bat', $output = array(), $return);

    return $return;

}

2) Is there a way to restart my webserver (apache) whilst keeping session variables that PHP needs available?

Thanks all

+3  A: 

The PHP process is killing a process that, in turn, kills the PHP process. It's like going back in time and murdering your parents before they gave birth to you. I don't see how it can work.

One has to ask why this functionality is necessary. If you must do it this way, you should look into scheduling a service restart from the script. I don't know if this is possible via PHP and Windows.

webbiedave
I thought the batch script will execute and stop and start apache. I just need that PHP script to die as soon as its tried to be stoped. Is there something that is opposite to `ignore_user_abort` for a process?!?
Abs
+1  A: 

The problem is related to the fact that exec waits for the process to end, but the process actually kills PHP so the whole thing gets stuck.

Running stop.bat as a background process should fix it. (here how to run a background process on Windows)

Davide
Thank you Davide. I made use of `WScript.Shell` - this is only a windows solution and its what I needed.
Abs