我正在使用Laravel Queues with beanstalkd。我有以下代码:
$user_id = Auth::user()->id;
Queue::push(function($job)
{
solve_simplex();
$job->delete();
});
其中solve_simplex()是我在PHP中添加的自定义函数作为扩展。
作业是排队的,但当我想运行php artisan queue:work时,它以:
结束php artisan queue:work
PHP Fatal error: Call to undefined function solve_simplex() in /var/www/my_site/vendor/jeremeamia/SuperClosure/src/Jeremeamia/SuperClosure/SerializableClosure.php(99) : eval()'d code on line 2
PHP Stack trace:
PHP 1. {main}() /var/www/my_site/artisan:0
PHP 2. SymfonyComponentConsoleApplication->run() /var/www/my_site/artisan:59
PHP 3. SymfonyComponentConsoleApplication->doRun() /var/www/my_site/vendor/symfony/console/Symfony/Component/Console/Application.php:121
PHP 4. SymfonyComponentConsoleApplication->doRunCommand() /var/www/my_site/vendor/symfony/console/Symfony/Component/Console/Application.php:191
PHP 5. IlluminateConsoleCommand->run() /var/www/my_site/vendor/symfony/console/Symfony/Component/Console/Application.php:887
PHP 6. SymfonyComponentConsoleCommandCommand->run() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Console/Command.php:96
PHP 7. IlluminateConsoleCommand->execute() /var/www/my_site/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:241
PHP 8. IlluminateQueueConsoleWorkCommand->fire() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Console/Command.php:108
PHP 9. IlluminateQueueWorker->pop() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:64
PHP 10. IlluminateQueueWorker->process() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:71
PHP 11. IlluminateQueueJobsBeanstalkdJob->fire() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:119
PHP 12. IlluminateQueueJobsJob->resolveAndFire() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Queue/Jobs/BeanstalkdJob.php:50
PHP 13. IlluminateQueueClosure->fire() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:96
PHP 14. JeremeamiaSuperClosureSerializableClosure->__invoke() /var/www/my_site/vendor/laravel/framework/src/Illuminate/Queue/IlluminateQueueClosure.php:16
PHP 15. ReflectionFunction->invokeArgs() /var/www/my_site/vendor/jeremeamia/SuperClosure/src/Jeremeamia/SuperClosure/SerializableClosure.php:64
PHP 16. JeremeamiaSuperClosureSerializableClosure::{closure:/var/www/my_site/vendor/jeremeamia/SuperClosure/src/Jeremeamia/SuperClosure/SerializableClosure.php(99) : eval()'d code:1-4}() / var/www/my_site/vendor/jeremeamia/SuperClosure/src/Jeremeamia/SuperClosure/SerializableClosure.php:64
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to undefined function solve_simplex()","file":"/var/www/my_site/vendor/jeremeamia/ SuperClosure/src/Jeremeamia/SuperClosure/SerializableClosure.php(99) : eval()'d code","line":2}}
它看起来像我的扩展没有加载。但它并不只在闭包中加载。如果我在正常的laravel代码中运行函数solve_simpex()(例如在控制器中),则它可以工作并加载扩展....
我找到了一个解决方案。问题是超闭包是通过以下命令调用的:
php工匠队列:工作
它是通过CLI调用的,不知道为什么它不加载扩展。
解决方案是使用-d参数运行artisan:
php -dextension = solveSimplex。So artisan queue:work
我需要让php CLI加载扩展名