當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。