我使用 Laravel/Lumen。我设置了一个简单的工作来发送短信:
<?php
namespace App\Jobs;
class SendDepositSMSAlertJob extends Job
{
private $numbers;
private $account;
private $type;
private $amount;
private $date;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($account, $type, $amount, $date, $numbers)
{
$this->numbers = $numbers;
$this->account = $account;
$this->type = $type;
$this->amount = $amount;
$this->date = $date;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
foreach ($this->numbers as $number) {
// Settings
$url = "https://api.xxxxx.com/v3/messages/send";
$from = "XX";
$message = urlencode($this->account." has been credited with a " . $this->type . " deposit of GHs " . $this->amount . " on " . $this->date);
$client_id = "xxxxxx";
$client_secret = "xxxxxxx";
$query_string = "?From=".$from."&To=".$number."&Content=".$message."&ClientId=".$client_id."&ClientSecret=".$client_secret."&RegisteredDelivery=true";
$response = @file_get_contents($url.$query_string);
}
}
}
现在,每当记录保存在我的控制器中时,我都会调度作业:
$this->dispatch(new SendDepositSMSAlertJob($bank . ' - ' . $acNumber, $depositType, $depositAmount, $reportDate, $telNumbers));
现在我的 kernel.php 中有以下设置:
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\JK\Dingo\Api\Console\Commands\RouteListCommand::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// Run once a minute
$schedule->command('queue:work')->everyMinute()->withoutOverlapping();
}
}
在我的 cPanel 中,我设置了以下 cron 作业:
php -d register_argc_argv=On /home/xxxxxx/xxxxxx/artisan schedule:run
上面的命令设置为每分钟运行一次。
问题 这个设置根本不适合我。在我的 Bluehost VPS 上,它导致我的服务器多次崩溃,迫使我重新启动。显然它占用了这么多内存,我不明白为什么,支持也无法帮助我。让我澄清一下,它有效,但导致我的服务器每天至少崩溃两次。
所以认为这与我的托管有关,我在其他地方(SiteGround)购买了另一个托管。现在我什至无法让 cron 工作。每次 cron 执行时都会发送到我的邮件:
Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Resource temporarily unavailable' in /home/xxxxx/xxxxx/vendor/symfony/console/Application.php:941
Stack trace:
#0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(2, 'proc_open(): fo...', '/home/abc17060/...', 941, Array)
#1 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(941): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(729): Symfony\Component\Console\Application->getSttyColumns()
#3 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(690): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(623): Symfony\Component\Console\Application->getTerminalWidth()
#5 /home/xxxxx/xxxxx/vendor/laravel/lumen-framework/src/Exceptions/Handler.php(147): Symfony\Component\Console\Application->renderException(Object(ErrorException), in /home/xxxxx/xxxxx/vendor/symfony/console/Application.php on line 941
Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Resource temporarily unavailable' in /home/xxxxx/xxxxx/vendor/symfony/console/Application.php:941
Stack trace:
#0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(2, 'proc_open(): fo...', '/home/abc17060/...', 941, Array)
#1 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(941): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(729): Symfony\Component\Console\Application->getSttyColumns()
#3 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(690): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /home/xxxxx/xxxxx/vendor/symfony/console/Application.php(623): Symfony\Component\Console\Application->getTerminalWidth()
#5 /home/xxxxx/xxxxx/vendor/laravel/lumen-framework/src/Exceptions/Handler.php(147): Symfony\Component\Console\Application->renderException(Object(Symfony\Component in /home/xxxxx/xxxxx/vendor/symfony/console/Application.php on line 941
现在我不知道是什么原因造成的,也不知道如何解决。我相信我已按照文档中的所有说明进行操作,并且无法判断我在这里做错了什么。我已经完成了研究并联系了两家托管公司的支持人员,但仍然......
这是我从支持人员那里收到的最后一条消息:
我尝试运行 cron 几次,但它没有任何预定的命令要运行:
xxxxxx@c27664 [~/xxxxx]# php -d register_argc_argv=On /home/xxxxxx/xxxxxx/artisan schedule:run
No scheduled commands are ready to run.
此外,我再次增加了限制。我为脚本的执行设置了 300 秒和 2048MB memory_limit。
请再试一次,如果您需要任何帮助,请不要犹豫更新票证。
Lumen和jobs有什么问题吗?我在 Laravel 5.1 中成功运行命令这里发生了什么。
或者,如果有更简单或有效的方法可以通过 cron 使用常规 PHP 执行此脚本,请告诉我如何。