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

Recommended Answers

All 3 Replies

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

Use this syntax:

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

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:

<?php
// Do some stuff
eval(file_get_contents('?>'.'another_php_scrpt.php'));
// 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.