• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP time_nanosleep函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中time_nanosleep函数的典型用法代码示例。如果您正苦于以下问题:PHP time_nanosleep函数的具体用法?PHP time_nanosleep怎么用?PHP time_nanosleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: initScan

 /**
  * Init scan process.
  * Solution for realtime output find on: http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php
  * Maybe ugly, but sometimes at 3AM it's only what is getting out of head ;-)
  */
 public function initScan()
 {
     $view = new Views('templates/head.tpl.php');
     $view->set('class', 'scanner');
     print $view->render();
     set_time_limit(0);
     $handle = popen(PHP . " scanner.php " . $this->project_id, "r");
     if (ob_get_level() == 0) {
         ob_start();
     }
     while (!feof($handle)) {
         $buffer = fgets($handle);
         $buffer = trim(htmlspecialchars($buffer));
         $data = explode(';', $buffer);
         switch ($data[0]) {
             case 'FOUND':
                 print "<div class=\"infobox\"><h3>Found something</h3><p><strong>Time:</strong> " . $data[1] . "<br><strong>Filter name:</strong> " . $data[2] . "<br><strong>Line:</strong> " . $data[3] . "<br><strong>File:</strong> " . $data[4] . "</p><a href=\"/report/" . $data[5] . "\" target=\"_blank\"><span class=\"button warning_button\" style=\"\">Show report</span></a></div>";
                 break;
             case 'NOT_FOUND':
                 print "<div class=\"infobox\"><h3>WOW!</h3><p>Scanner didn't found anything. So your project is sooo secure. You are security mastah, or the filters are too weak ;-) Anyway, I recommend to do a manual code review, to be 100% sure ;-)</p></div>";
                 break;
             case 'SCANNED':
                 print "<div class=\"infobox\"><h3>Hmmmm...</h3><p>Your project has been scanned before. Please go to project to check your reports. <br><a href=\"/show/" . $this->project_id . "\" target=\"_parent\"><span class=\"button\">Go to project page</span></a></p></div>";
                 break;
         }
         ob_flush();
         flush();
         time_nanosleep(0, 10000000);
     }
     pclose($handle);
     ob_end_flush();
 }
开发者ID:beejhuff,项目名称:sec-scanner,代码行数:37,代码来源:Scanner.php


示例2: millisecond

 /**
  * Sleeps for the given amount of milliseconds
  *
  * @param $ms
  */
 public static function millisecond($ms)
 {
     if (($sec = (int) ($ms / 1000)) > 0) {
         $ms = $ms % 1000;
     }
     time_nanosleep($sec, $ms * 1000000);
 }
开发者ID:c2is,项目名称:ApnsSender,代码行数:12,代码来源:Sleep.php


示例3: QueryNominatim

 function QueryNominatim($query, $countryCodes = [], $searchLimit = "10", $boundingBox = [])
 {
     $curlString = self::NOMINATIM_URL_BASE . '/search?format=json';
     $curlString .= '&limit=' . $searchLimit;
     $curlString .= '&email=' . self::NOMINATIM_EMAIL;
     $curlString .= '&addressdetails=1';
     if ($countryCodes) {
         $curlString .= "&countrycodes=" . implode(',', $countryCodes);
     }
     if ($boundingBox) {
         $curlString .= "&viewbox=" . $boundingBox["west"];
         $curlString .= "," . $boundingBox["north"];
         $curlString .= "," . $boundingBox["east"];
         $curlString .= "," . $boundingBox["south"];
         $curlString .= "&bounded=1";
     }
     $curlString .= '&q=' . $query;
     if (printOutput()) {
         echo "<br>Executing query: " . $curlString . "<br>";
     }
     if (self::LIMIT_QUERIES) {
         while ($this->lastQueryTime + 1.0 > microtime(true)) {
             time_nanosleep(0, 10000);
         }
     }
     $this->lastQueryTime = microtime(true);
     return json_decode(Connectivity::runCurl($curlString), true);
 }
开发者ID:spotzi,项目名称:Geotagger,代码行数:28,代码来源:Geotagger.php


示例4: send

 public function send($labels)
 {
     foreach ($labels as $label) {
         time_nanosleep(0, 100000000);
         $this->connector->send($label);
     }
 }
开发者ID:robmachado,项目名称:webetiq,代码行数:7,代码来源:Job.php


示例5: run

 public function run($args)
 {
     while (1) {
         $this->_logger->log(__METHOD__ . ' ' . 'NEW CIRCULE');
         $this->dataExchange();
         time_nanosleep(0, 20000000);
     }
 }
开发者ID:anton-itscript,项目名称:WM-Web,代码行数:8,代码来源:TcpServerCommand.php


示例6: setUp

 /**
  * setUp test suite
  *
  * @return void
  */
 public function setUp()
 {
     $options = new ConnectionOptions();
     if (!self::$isGnatsd) {
         time_nanosleep(2, 0);
         $options->port = 4222;
     }
     $this->c = new Nats\Connection($options);
     $this->c->connect();
 }
开发者ID:pprasse,项目名称:phpnats,代码行数:15,代码来源:ConnectionTest.php


示例7: setUp

 /**
  * setUp test suite
  *
  * @return void
  */
 public function setUp()
 {
     $options = new ConnectionOptions();
     if (!self::$isGnatsd) {
         time_nanosleep(1, 700000000);
         $options->setPort(4222);
     }
     $this->c = new Nats\Connection($options);
     $this->c->connect();
 }
开发者ID:aquilax,项目名称:phpnats,代码行数:15,代码来源:ConnectionTest.php


示例8: isProcessRunning

 private static function isProcessRunning($pid)
 {
     try {
         $output = shell_exec("ps -p  {$pid}");
         if (count(preg_split("/\n/", $output)) > 2) {
             time_nanosleep(0, 500000);
             return true;
         }
     } catch (Exception $e) {
     }
     return false;
 }
开发者ID:arteam,项目名称:orders-system,代码行数:12,代码来源:AppTest.php


示例9: reserveRDaemon

function reserveRDaemon()
{
    global $projectHome;
    for ($counter = 1; $counter <= 30; $counter++) {
        // wait up to 3 seconds
        $reservedRInstance = reserveRInstance();
        if ($reservedRInstance != NULL) {
            return $reservedRInstance;
        }
        time_nanosleep(0, 100000000);
    }
    return null;
}
开发者ID:EU-OSHA,项目名称:esener,代码行数:13,代码来源:reserve.php


示例10: testGetTime

 public function testGetTime()
 {
     $timer = new Timer();
     time_nanosleep(0, 200000000);
     $result1 = $timer->getTime();
     time_nanosleep(0, 300000000);
     $result2 = $timer->getTime(true);
     time_nanosleep(0, 100000000);
     $result3 = $timer->getTime();
     $this->assertTrue(0.2 <= $result1 && $result1 <= 0.205, $result1);
     $this->assertTrue(0.5 <= $result2 && $result2 <= 0.505, $result2);
     $this->assertTrue(0.1 <= $result3 && $result3 <= 0.105, $result3);
 }
开发者ID:BGCX261,项目名称:zibo-svn-to-git,代码行数:13,代码来源:TimerTest.php


示例11: __construct

 public function __construct()
 {
     $this->filepath__ = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'nosqlvars' . DIRECTORY_SEPARATOR . $this->filename__;
     if (!file_exists($this->filepath__)) {
         $array = $this->initFieldsValues();
         file_put_contents($this->filepath__, json_encode($array, true));
     }
     $this->fileData__ = json_decode(file_get_contents($this->filepath__), true);
     while ($this->fileData__ == false) {
         time_nanosleep(0, 200000000);
         $this->fileData__ = json_decode(file_get_contents($this->filepath__), true);
     }
     $this->setValuesAsProperties();
 }
开发者ID:anton-itscript,项目名称:WM-Web,代码行数:14,代码来源:PFileModel.php


示例12: await

 /**
  * Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted.
  *
  * @param int $timeout
  * @param TimeUnit|null $unit the timeunit of the given timeout
  * @return bool true if the count reached zero and false if the waiting time elapsed before the count reached zero
  */
 public function await($timeout = 0, TimeUnit $unit = null)
 {
     if (null !== $unit) {
         $timeout = $unit->toMicros($timeout);
     }
     $timeoutAt = microtime(true) + $timeout / 1000000;
     while (0 != $this->count) {
         if ($timeout > 0 && microtime(true) > $timeoutAt) {
             return false;
         }
         time_nanosleep(0, 1);
     }
     return true;
 }
开发者ID:prolic,项目名称:concurrent-php-utils,代码行数:21,代码来源:CountDownLatch.php


示例13: waitForLock

 private function waitForLock($failSafe = false)
 {
     $wait_counter = 0;
     while (file_exists($this->email_file_loc . ".lock")) {
         $wait_counter++;
         if ($wait_counter > 100) {
             if (!$failSafe) {
                 throw new Exception("Email time-out waiting for lock", 1);
             } else {
                 return false;
             }
         }
         time_nanosleep(0, 100000000);
         //sleep for a 10th of a second.
     }
     return true;
 }
开发者ID:AngryShrimp,项目名称:CME495_Design_IMS,代码行数:17,代码来源:IMSEmail.php


示例14: uploadOrders

 protected function uploadOrders($orders)
 {
     if (sizeof($orders)) {
         $orders = array_chunk($orders, $this->config['retailcrm_order_chunk_size']);
         foreach ($orders as $chunk) {
             try {
                 $result = $this->crmClient->ordersUpload($chunk);
                 if (!$result->isSuccessful()) {
                     $this->writeLog('ordersUpload: ' . $result['errorMsg'] . (isset($result['errors']) ? ': ' . json_encode($result['errors']) : ''));
                 }
                 time_nanosleep(0, 200000000);
             } catch (\RetailCrm\Exception\CurlException $e) {
                 $this->writeLog('ordersUpload: ' . $e, 'error');
             }
         }
         return true;
     } else {
         return false;
     }
 }
开发者ID:retailcrm,项目名称:tiu-client,代码行数:20,代码来源:ApiHelper.php


示例15: cache_get

function cache_get($url, $cache_file, $verbose = true, $update = false, $cache_life = 43200)
{
    $message = '';
    $content = '';
    clearstatcache();
    if ($url == '') {
        $message .= '[empty url]';
    } else {
        if (file_exists($cache_file) && time() - filemtime($cache_file) <= $cache_life) {
            $message .= '[use cache]';
            $content = @file_get_contents($cache_file);
        } else {
            $message .= '[update cache : ';
            if ($update && file_exists($cache_file) && curl_get_file_size($url) <= filesize($cache_file)) {
                $message .= 'cache file is already bigger';
                $content = @file_get_contents($cache_file);
            } else {
                if (($content = curl_download($url)) !== false) {
                    // @file_get_contents($url)
                    rmkdir(dirname($cache_file));
                    if (($size = @file_put_contents($cache_file, $content)) === false) {
                        $message .= 'not updatable (' . $cache_file . ')';
                    } else {
                        $message .= 'updated (' . human_filesize($size) . ')';
                    }
                    if (strpos($url, 'http://www.magic-ville.com') !== false) {
                        time_nanosleep(0, 500000000);
                    }
                    // Avoid anti-leech mechanism on MV (30 queries every 15 sec)
                } else {
                    $message .= 'not downloadable (' . $url . ')';
                }
            }
            $message .= ']';
        }
    }
    if ($verbose) {
        echo $message;
    }
    return $content;
}
开发者ID:OlivierLamiraux,项目名称:mtgas,代码行数:41,代码来源:lib.php


示例16: acquireLock

 /**
  * Check for lock file and create new one
  * if no file exists.
  * 
  * Other wise wait maximumg of $timeout
  * or force it if lockRunTime exceeded $maxRunTime
  * 
  * @param string $filename Lock file
  * @param number $timeout In seconds
  * @param number $maxRunTime In seconds
  * @throws Exception
  * @return boolean
  */
 public function acquireLock($filename, $timeout = 5, $maxRunTime = 3600)
 {
     if ($this->_filename) {
         throw new Exception('Lock already in place.');
     }
     if (file_exists($filename)) {
         $data = unserialize(file_get_contents($filename));
         // kill if process last touch exceeds max run time
         if ($data['last_touch'] + $maxRunTime < time()) {
             unlink($filename);
         } else {
             if ($timeout <= 0) {
                 return false;
             } else {
                 // wait till time out is reached
                 $time = microtime(true);
                 while (1) {
                     time_nanosleep(0, 100000);
                     if (!file_exists($filename)) {
                         break;
                     } else {
                         if ($timeout < microtime(true) - $time) {
                             return false;
                         }
                     }
                 }
             }
         }
     }
     $this->_data = array('start' => time(), 'last_touch' => time(), 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null, 'uri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null);
     //file_put_contents($filename, $data)
     $this->_fileHandle = fopen($filename, 'c+');
     $this->_filename = realpath($filename);
     if (!$this->_filename) {
         throw new Exception('Failed to create lock, file could not be created.');
     }
     // what ever happens, make sure to kill the current lock file
     register_shutdown_function(array('Mzax_Once', 'unlinkFile'), $this->_filename);
     $this->touch();
     return true;
 }
开发者ID:jsiefer,项目名称:emarketing,代码行数:54,代码来源:Once.php


示例17: send_ipc_cmd

function send_ipc_cmd($id, $cmd) {
	$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
	
	if (!@socket_connect($socket, "/tmp/IRC_" . $id . ".sock")) {
		echo "S_ERROR socket_connect";
		return;
	}

	/*if (!socket_set_nonblock($socket)) {
		echo 'error stream_set_blocking';
		return(1);
	}*/
	
	$buf = $cmd . "\n";
	$ret = socket_write($socket, $buf, strlen($buf));

	$buf = '';
	$sockarr = array($socket);
	while (1) {
		$in_buf = @socket_read($socket, 8192, PHP_NORMAL_READ);
		
		if (strlen(trim($in_buf)) == 0)
			time_nanosleep(0, 499999999);
		
		if ($in_buf === false || socket_last_error($socket) == 104) {
			// dead socket
			socket_close($socket);
			break;
		}
		
		if (trim($in_buf) == "EOR")
			break;
		
		$buf .= $in_buf;
	}

	socket_close($socket);
	return($buf);
}
开发者ID:radixcl,项目名称:powerirc,代码行数:39,代码来源:common.php


示例18: enforce_min_exec_time

 /**
  * Enforce the minimum execution time
  *
  * @param    bool $log Should I log what I'm doing? Default is true.
  */
 public function enforce_min_exec_time($log = true)
 {
     // Try to get a sane value for PHP's maximum_execution_time INI parameter
     if (@function_exists('ini_get')) {
         $php_max_exec = @ini_get("maximum_execution_time");
     } else {
         $php_max_exec = 10;
     }
     if ($php_max_exec == "" || $php_max_exec == 0) {
         $php_max_exec = 10;
     }
     // Decrease $php_max_exec time by 500 msec we need (approx.) to tear down
     // the application, as well as another 500msec added for rounding
     // error purposes. Also make sure this is never gonna be less than 0.
     $php_max_exec = max($php_max_exec * 1000 - 1000, 0);
     // Get the "minimum execution time per step" Akeeba Backup configuration variable
     $configuration = AEFactory::getConfiguration();
     $minexectime = $configuration->get('akeeba.tuning.min_exec_time', 0);
     if (!is_numeric($minexectime)) {
         $minexectime = 0;
     }
     // Make sure we are not over PHP's time limit!
     if ($minexectime > $php_max_exec) {
         $minexectime = $php_max_exec;
     }
     // Get current running time
     $elapsed_time = $this->getRunningTime() * 1000;
     // Only run a sleep delay if we haven't reached the minexectime execution time
     if ($minexectime > $elapsed_time && $elapsed_time > 0) {
         $sleep_msec = $minexectime - $elapsed_time;
         if (function_exists('usleep')) {
             if ($log) {
                 AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_msec} msec, using usleep()");
             }
             usleep(1000 * $sleep_msec);
         } elseif (function_exists('time_nanosleep')) {
             if ($log) {
                 AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_msec} msec, using time_nanosleep()");
             }
             $sleep_sec = floor($sleep_msec / 1000);
             $sleep_nsec = 1000000 * ($sleep_msec - $sleep_sec * 1000);
             time_nanosleep($sleep_sec, $sleep_nsec);
         } elseif (function_exists('time_sleep_until')) {
             if ($log) {
                 AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_msec} msec, using time_sleep_until()");
             }
             $until_timestamp = time() + $sleep_msec / 1000;
             time_sleep_until($until_timestamp);
         } elseif (function_exists('sleep')) {
             $sleep_sec = ceil($sleep_msec / 1000);
             if ($log) {
                 AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_sec} seconds, using sleep()");
             }
             sleep($sleep_sec);
         }
     } elseif ($elapsed_time > 0) {
         // No sleep required, even if user configured us to be able to do so.
         if ($log) {
             AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "No need to sleep; execution time: {$elapsed_time} msec; min. exec. time: {$minexectime} msec");
         }
     }
 }
开发者ID:01J,项目名称:topm,代码行数:67,代码来源:timer.php


示例19: wait

 protected function wait($interval, $callback)
 {
     $seconds = floor($interval);
     $nanoseconds = ($interval - $seconds) * 1000000000;
     time_nanosleep($seconds, $nanoseconds);
     return $callback();
 }
开发者ID:qieangel2013,项目名称:zys,代码行数:7,代码来源:Socket_Client.php


示例20: importWeather

 /**
  * Import weather data to data base
  *
  * @param InputInterface $input, OutputInterface $output
  */
 protected function importWeather(InputInterface $input, OutputInterface $output)
 {
     $stationManager = $this->getContainer()->get('weather.guy.station.manager');
     $infoManager = $this->getContainer()->get('weather.guy.information.manager');
     $remoteAemet = $this->getContainer()->get('weather.guy.wunder.remote');
     $result = $remoteAemet->stationList();
     $output->writeln("<info>Processing ...</info>");
     $count = 0;
     foreach ($result as $key => $onestation) {
         time_nanosleep('7', '10');
         $count++;
         $autoFlush = $count % self::BATCH_SIZE === 0;
         // Check if station with name = $info['name'] exists.
         $station = $stationManager->findStationByName($onestation->name);
         if (null === $station) {
             $this->importStation($input, $output);
         }
         // Weather information Object
         $date = new \DateTime('now');
         try {
             $weatherInfo = $infoManager->create($station, $date);
         } catch (\Exception $exc) {
             // Weather information for $station at $date exists.
             continue;
         }
         $info = $infoManager->findWeatherInformation($station, $date);
         if (null === $info) {
             $data = $remoteAemet->stationInfo($onestation->zmw);
             $avg_temp = floor(($data['weather_result'][0]->high->celsius + $data['weather_result'][0]->low->celsius) / 2);
             $weatherInfo->setMaxTemperature($this->getTemperatureOf($data['weather_result'][0]->high->celsius));
             $weatherInfo->setMinTemperature($this->getTemperatureOf($data['weather_result'][0]->low->celsius));
             $weatherInfo->setAvgTemperature($this->getTemperatureOf($avg_temp));
             $weatherInfo->setPrecipitation($this->getPrecipitationOf($data['weather_result'][0]->qpf_allday->mm));
             $weatherInfo->setSunshine($this->getSunshineOf($data['atronomy_result']));
             $infoManager->save($weatherInfo, $autoFlush);
             $output->writeln("Weather information for station <info>'{$onestation->name}'</info> ,  at <info>{$date->format('d-m-Y')}</info> <comment>imported</comment>");
         }
     }
 }
开发者ID:rastydnb,项目名称:WeatherGuyBundle,代码行数:44,代码来源:ImportWunderWeatherCommand.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP time_since函数代码示例发布时间:2022-05-23
下一篇:
PHP time_format函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap