本文介绍了Laravel需要Mcrypt PHP扩展。不工作cron工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我遇到这个问题,就像许多其他人一直没有解决方案一样。



问题:cron发出的命令任务不运行并给出消息: Laravel需要Mcrypt PHP扩展。



code> artisan ,他们工作正常。我在OSX 10.8上使用MAMP。



我已经四次检查我的 .bash_profile ,以确保正确的PATH设置它是: export PATH = / Applications / MAMP / bin / php / php5.4.4 / bin:$ PATH 。由确认,其中php 在终端。 php -v 确认正在使用PHP 5.4.4。 php -i 确认已安装并启用mcrypt扩展。甚至添加 die(phpversion()。PHP_EOL); 到 vendor / laravel / framework / src / Illuminate / Foundation / start.php 它确认它使用正确的版本。



所以我被骗了。我不知道为什么cronjobs不能识别正确的PHP版本或mcrypt扩展安装。


解决方案

不要依赖通过.bash_profile设置cronjob的PATH(它是一个shell特性和cronjobs不是通过shell运行),应该使用类似

  * * * * * / Applications / MAMP / php / php5.4.4 / bin / php-something? /path/to/vendor/laravel/framework/src/Illuminate/Foundation/start.php 

A测试可能是这样的:

 #/tmp/test.php 
<?php file_put_contents tmp / a_test',`id`。\\\
.var_export($ _ ENV,true)。\\\
.var_export(extension_loaded('mcrypt'),true)
#in crontab
* * * * * /Applications/MAMP/bin/php/php5.4.4/bin/php-something? /tmp/test.php

运行 php /tmp/test.php 一次手动来发现你运行脚本之间的区别,和cron;并且总是尝试在crontab中使用绝对路径(在这种情况下为您的PHP的二进制)。


So I am plagued with this issue like many others have been but with no solution.

The Issue: commands issued by a cron task do not run and give the message: Laravel requires the Mcrypt PHP extension.

I can run commands through artisan and they work fine. I am using MAMP on OSX 10.8.

I've quadrupal checked my .bash_profile to ensure the correct PATH is set which is: export PATH=/Applications/MAMP/bin/php/php5.4.4/bin:$PATH. Confirmed by which php in terminal. php -v confirms PHP 5.4.4 is being used. php -i confirms mcrypt extension is installed and enabled. Even adding die(phpversion().PHP_EOL); to vendor/laravel/framework/src/Illuminate/Foundation/start.php it's confirmed that it's using the correct version.

So I'm stumped. I don't know why cronjobs aren't recognizing either the correct PHP version or that the mcrypt extension is installed. What can I try?

解决方案

Don't rely on PATH being set for cronjob through .bash_profile (it's a shell feature and cronjobs are not running through a shell), you should rather use something like

* * * * * /Applications/MAMP/bin/php/php5.4.4/bin/php-something? /path/to/vendor/laravel/framework/src/Illuminate/Foundation/start.php

A test could be something like this:

# /tmp/test.php
<?php file_put_contents('/tmp/a_test', `id`."\n".var_export($_ENV, true)."\n".var_export(extension_loaded('mcrypt'), true));
# in crontab
* * * * * /Applications/MAMP/bin/php/php5.4.4/bin/php-something? /tmp/test.php

Run php /tmp/test.php one time manually to spot the differences between you running the script, and cron; and always try to use absolute paths in crontab (in this case to your php binary).

这篇关于Laravel需要Mcrypt PHP扩展。不工作cron工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 15:34