当前位置: 首页>>代码示例>>PHP>>正文


PHP Cron::setDatabaseLogging方法代码示例

本文整理汇总了PHP中Cron::setDatabaseLogging方法的典型用法代码示例。如果您正苦于以下问题:PHP Cron::setDatabaseLogging方法的具体用法?PHP Cron::setDatabaseLogging怎么用?PHP Cron::setDatabaseLogging使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cron的用法示例。


在下文中一共展示了Cron::setDatabaseLogging方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPreventOverlapping

 /**
  *  Test the prevent job overlapping functionality
  *
  *  @covers \Liebig\Cron\Cron::run
  * @covers \Liebig\Cron\Cron::setEnablePreventOverlapping
  * @covers \Liebig\Cron\Cron::setDisablePreventOverlapping
  * @covers \Liebig\Cron\Cron::isPreventOverlapping
  */
 public function testPreventOverlapping()
 {
     // Disable database logging because we need this later
     Cron::setDatabaseLogging(false);
     // Getting storage path with Laravel3 fallback
     $storagePath = "";
     if (function_exists('storage_path')) {
         $storagePath = storage_path();
     } else {
         if (function_exists('path')) {
             $storagePath = path('storage');
         } else {
             throw new RuntimeException('Could not find the path to Laravels storage directory.');
         }
     }
     // We disabled this at startup -> have a look at the setDefaultConfigValues method
     $this->assertEquals(false, Cron::isPreventOverlapping());
     // Enabling prevention
     Cron::setEnablePreventOverlapping();
     $this->assertEquals(true, Cron::isPreventOverlapping());
     // Disabling prevention
     Cron::setDisablePreventOverlapping();
     $this->assertEquals(false, Cron::isPreventOverlapping());
     // Sorry, for windows 7 servers unlink and touch does not work
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         return;
     }
     // Create a example job which writes to the $lockfileExists variable if a lock file exists
     $lockfileExists;
     Cron::add('testlockfile', "* * * * *", function () use(&$lockfileExists, $storagePath) {
         if (file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock')) {
             $lockfileExists = true;
         } else {
             $lockfileExists = false;
         }
     });
     Cron::run();
     $this->assertEquals(false, $lockfileExists);
     $this->assertEquals(false, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
     $lockfileExists = "";
     Cron::setEnablePreventOverlapping();
     $this->assertEquals(true, Cron::isPreventOverlapping());
     Cron::run();
     $this->assertEquals(true, $lockfileExists);
     $this->assertEquals(false, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
     // Simulate two run calls at the same time
     touch($storagePath . DIRECTORY_SEPARATOR . 'cron.lock');
     $this->assertEquals(true, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
     Cron::setDatabaseLogging(true);
     $lockfileExists = "Not called";
     $report = Cron::run();
     $this->assertEquals("Not called", $lockfileExists);
     $this->assertEquals(-1, $report['runtime']);
     $newManagerFind = \Liebig\Cron\Models\Manager::find(1);
     $this->assertNotNull($newManagerFind);
     $this->assertEquals(-1, $newManagerFind->runtime);
     unlink($storagePath . DIRECTORY_SEPARATOR . 'cron.lock');
     $this->assertEquals(false, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
 }
开发者ID:hilltool,项目名称:cron,代码行数:67,代码来源:CronTest.php


注:本文中的Cron::setDatabaseLogging方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。