4

I am using shell_exec command to run my artisan commands in the background. But when I run shell_exec in production server.

The route code as follows

Route::get('/test/exec', function () {
    echo shell_exec('php ../artisan migrate:status 2>&1; echo $?');
});

it throws me error as follows.

PHP Fatal error: Cannot redeclare class Illuminate\Support\Traits\Macroable in /var/www/production/bootstrap/cache/compiled.php on line 6109 255

But when I run the same command in my local I got the output.

  • Laravel versin - 5.1.46
  • php version - PHP 5.5.9
  • os version - ubuntu 14.04

These are same on both servers. Where things went wrong. Please, some one helps me with this.

Tamizharasan
  • 293
  • 1
  • 5
  • 18
  • Try removing individual composer dependencies, it may be possible that one of them isn't using an autoloader and is including things manually. Alternatively, google 'debugging with xdebug' and step through the code until it requires this file and throws the fatal error, although this requires PHP knowledge and not just Laravel. – Jimbo Sep 20 '17 at 10:31

2 Answers2

2

For this error try to run the following commands:

php artisan clear-compiled
php artisan optimize

this should regenerate compiled.php file.

As for executing artisan commands from within your code there are better ways than using shell_exec - for example using Laravel build in support for programmatically executing commands

Michal Bieda
  • 954
  • 5
  • 13
0

The error

% Cannot redeclare class %

also occurs when you inject a class that has the same name as the one you are actively editing/modifying.

In your case, please make sure that you have not injected a class with the name "Macroable" elsewhere. If you have, make sure that the namespace is unique.

hannes_rd
  • 150
  • 1
  • 8