简体   繁体   中英

Envoyer Deployment with custom artisan command fails

I have a problem deploying my project with envoyer which executes an artisan-command I created.

The command gets all my users, performs another artisan command ( $this->call('command') ) and performs it actions by iterating through all the users.

The problems lies here:

    foreach($usernames as $username) {
        shell_exec('php ' . base_path('artisan') . ' command ' . $username . ' > /dev/null 2>/dev/null &');
    }

This command starts a script in the background. Its getting executed without any problems manually and doesn't end in a timeout (takes about 1s~ to execute) but in envoyer it wont stop running in the deploying step and fails in a timeout altough it executes flawless.

Additional informations:
For the reason why i'm running the script in the background:
The script im starting opens a socket which he will listen 24/7 until the user cancel it manually.

I've just created a smaller example to make sure it's all working fine:

File forever.php will keep an infinite loop printing something every 5 seconds:

<?php
while (true) {
  echo "I am still in the loop $argv[1]\n";
  sleep(5);
}

File script.php will call multiple instances of forever.php and detach from the parent process (same as what you did):

<?php
for ($i = 0; $i < 5; $i++) {
  shell_exec("php forever.php $i > /dev/null 2>/dev/null &");
}

When executing php script.php , obviously there's 5 instances of forever.php running. So your code seems fine (the part you've shown).

The only things I can think of in your case are:

  • 1 second is too long for a script to run on Envoyer?
  • Your loop is a foreach on all your users. Could it be you're generating too many processes in that loop? How many users do you have?
  • Could you print your command before executing it, and try it directly on the terminal, to see whether it's all working fine?

Hope it helps, if you need more help please provide some more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM