Is it possible to run command line exec in the foreground instead of the background with PHP?

Edited by petrovitch: bash was too restrictive

6 Years
Discussion Span
Last Post by edwinhermann

Of course. Usually it's in /usr/bin/php

Use this syntax:

/usr/bin/php[I] filename.php[/I]

I'm running PHP CLI and calling parent/child script by forking. The child scripts are running in background and are difficult to debug. They need to run in foreground. I was looking at the option of calling scripts using the exec command, but they run in background too. How can I run scripts called from a PHP script in foreground? My only other solution seems to be writing a shell script that calls the PHP program in a loop.

Another problem with this same script is finding out how to trap ctrl-c in PHP CLI. I have found numerous examples that work on the web, but not CLI.


Are the other scripts also PHP? If so, you can call them using veal.

Like this:

// Do some stuff
// Do other stuff  <-- this will only start when the other php script has finished executing

Then when you call this main script from CLI, the other php script will also be executed in due course but in the foreground.

Edited by edwinhermann: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.