0

I try to run my script:

$exec_string = '/usr/bin/node /www/laravel/sitemap';
exec($exec_string,$output);

My script work fine from terminal (chmod and chown == ok). But when I run it from exec it finished after first async task. Node:

function callAddLink()
{
     1..100 async_function() {

          code and code...

          IT STOPS HERE. NEXT ASYNC TASK NEVER CALLS!
     }
}

Why it can happen? Code works fine everywhere except php exec.

1 Answer 1

1

Adding an ampersand to the end of your command, will redirect the output stream until the program exits.

$exec_string = '/usr/bin/node /www/laravel/sitemap &';
exec($exec_string,$output);

The default behaviour for PHP exec function is to be synchronise/blocking (to wait until the program has exited before moving on). But when executing an asynchronous node CLI application it seems to return before the application has exited.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.