1

I have a simple php script that is runs via cli to start OpenVPN:

$system_string = "openvpn --config C:\\openvpn-config\\" . $config_file;
exec($system_string,$return_var);

file_put_contents('myfile.txt',$return_var);

The openvpn process starts with no issues (the openvpn console pops up in a separate window) but the output of the exec() is not getting saved to the file. In other words, the handle is not being returned back to the calling php script once the openvpn service starts. If I close the openvpn interface the php script continues though. I am on windows so pcntl is not an option unfortunately.

Any suggestions on how I can continue running the php scipt after starting the openvpn process?

maximus 69
  • 1,388
  • 4
  • 22
  • 35
  • Possible duplicate of [PHP exec() as Background Process (Windows Wampserver Environment)](http://stackoverflow.com/questions/5367261/php-exec-as-background-process-windows-wampserver-environment) – Aleksander Wons May 30 '16 at 10:52

1 Answers1

0

popen() seems to be quite inconsistent, I ultimately used the following to run a script in the background:

$commandString = 'start /b php daemon.php"'; 
pclose(popen($commandString, 'r'));

The would trigger the daemon.php and return the control back to the calling script so it can continue its execution.

maximus 69
  • 1,388
  • 4
  • 22
  • 35