exec does not work - apparently runs the same call file

Asked

Viewed 342 times

1

I have a time consuming script that prevents the execution of other processes while it does not finish.

As a solution, I decided to create a file that runs it by the exec command (Mkt-start.php). Thus:

exec('php -f mkt-exec.php > mkt.log &');

& (and commercial) is for that file Mkt-exec.php run in the background, so that the browser does not wait for the end of the execution.

But the result of Mkt.log is itself Mkt.start.php and not the Mkt-exec.php, resulting in an infinite loop of plays.

When I execute the command by shell (php -f mkt-exec.php > mkt.log &) works properly.

Does anyone know why this behavior?

Obs: The result is the same if you put the full file path and/or the full php path.

2 answers

3

  • 2

    +1 by reply, edited and removed what was irrelevant and added links, what I find more strange is the safe_mode work, you must be using PHP5.3 or older yet, something extremely unusual these days, even more than php5.3 is no longer maintained, being in 5.6 and 7.1

  • Exactly. It’s a client whose server is old (PHP 5.4) and safe_mode came active. We’re used to 7.0. But the customer paid for the system and not for the upgrade (not for lack of offer on our part), so rsssss

  • PHP 5.4 does not have safe_mode: http://php.net/manual/en/migration54.incompatible.php. See the first item Safe mode is no longer supported. Any Applications that rely on safe mode may need adjustment, in Terms of security., you must have more than one version of PHP.

1

You can add a header like this in the Mkt-exec.php file:

#!/usr/bin/php
<?php
// O resto do código

Give execution permission with chmod +x mkt-exec.php and run straight with the command exec(mkt-exec.php > mkt.log &)

Obs: The way /usr/bin/php must be the path to the PHP executable, you can run the command which php that he shows where he is.

  • Just a hint, both #!/usr/bin/php how much chmod +x mkt-exec.php would only be necessary if it were to execute the mkt-exec.php directly, needlessly type php ....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.