exec does not work - apparently executes the same call file

1

I have a lengthy script that prevents other processes from running while it does not finish.

As a workaround, I decided to create a file that executes it with the exec ( mkt-start.php ) command. So:

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

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

However, the result of mkt.log is mkt.start.php itself and not mkt-exec.php , resulting in an infinite loop of executions. / p>

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

Does anyone know why this behavior?

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

    
asked by anonymous 13.03.2017 / 17:00

2 answers

3

The problem was safe_mode of php, so exec works with php itself (php [file]) safe_mode can not be active.

13.03.2017 / 18:55
1

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

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

Give permission to execute with chmod +x mkt-exec.php and run it directly with the command exec(mkt-exec.php > mkt.log &)

Note: The /usr/bin/php path must be the PHP executable path, you can run the which php command that shows where it is.

    
13.03.2017 / 18:08