在另一个路由中调用路由(cron 作业测试)



我有这样的路线:

Route::get('cron_job/{param1}/{param2?}', function($param1 = NULL, $param2 = NULL)
{
    //do something here;
    echo "Im'm here with param". $param1;
});

我将这条路线用于 cron 作业,它工作正常。

但是现在,我想尝试使用另一条路由来测试它,如下所示:

Route::get('test_cron_job', function()
{
    do {
        $param = 1;
        // here I just want to call http://my_app.local/cron_job/$param1 
        $param++;
    } while ($param <10)
});

怎么办?在 cronjob 中,我使用:

links -dump http://my_app.local/cron_job/$param1 

但是如何在路由中的另一个路由中调用它.php以测试它呢?

您可以使用 file_get_content(url(;

$file = file_get_contents("http://www.example.com/{$param1}", false, $context);

让我们试试:

Route::get('test_cron_job', function()
{
   do {
      $param1 = 1;
      // here I just want to call http://my_app.local/cron_job/$param1
      redirect('/cron_job/'.$param1);
     $param++;
   } while ($param <10)
});

最新更新