本文整理匯總了PHP中Cron::setRunInterval方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cron::setRunInterval方法的具體用法?PHP Cron::setRunInterval怎麽用?PHP Cron::setRunInterval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cron
的用法示例。
在下文中一共展示了Cron::setRunInterval方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testRunWithTime
/**
* Test method for running cron jobs in the right time
*
* @covers \Liebig\Cron\Cron::run
*/
public function testRunWithTime()
{
$i = 0;
Cron::add('test1', '* * * * *', function () use(&$i) {
$i++;
return null;
});
$runResult1 = Cron::run();
$this->assertEquals(1, $i);
$this->assertEquals(0, $runResult1['errors']);
$this->assertEquals(1, count($runResult1['crons']));
$this->assertEquals('test1', $runResult1['crons'][0]['name']);
$this->assertEquals(null, $runResult1['crons'][0]['return']);
$this->assertEquals(-1, $runResult1['inTime']);
Cron::add('test2', '* * * * *', function () {
return 'return of test2';
});
$runResult2 = Cron::run();
$this->assertEquals(2, $i);
$this->assertEquals(1, $runResult2['errors']);
$this->assertEquals(2, count($runResult2['crons']));
$this->assertEquals('test1', $runResult2['crons'][0]['name']);
$this->assertEquals(null, $runResult2['crons'][0]['return']);
$this->assertEquals('test2', $runResult2['crons'][1]['name']);
$this->assertEquals('return of test2', $runResult2['crons'][1]['return']);
sleep(60);
$runResult3 = Cron::run();
$this->assertEquals(3, $i);
$this->assertEquals(true, $runResult3['inTime']);
sleep(25);
$runResult4 = Cron::run();
$this->assertEquals(4, $i);
$this->assertEquals(false, $runResult4['inTime']);
sleep(95);
$runResult5 = Cron::run();
$this->assertEquals($i, 5);
$this->assertEquals(false, $runResult5['inTime']);
Cron::setRunInterval(2);
sleep(120);
$runResult6 = Cron::run();
$this->assertEquals($i, 6);
$this->assertEquals(true, $runResult6['inTime']);
}