本文整理汇总了PHP中time_nanosleep函数的典型用法代码示例。如果您正苦于以下问题:PHP time_nanosleep函数的具体用法?PHP time_nanosleep怎么用?PHP time_nanosleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了time_nanosleep函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
示例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);
}
示例4: send
public function send($labels)
{
foreach ($labels as $label) {
time_nanosleep(0, 100000000);
$this->connector->send($label);
}
}
示例5: run
public function run($args)
{
while (1) {
$this->_logger->log(__METHOD__ . ' ' . 'NEW CIRCULE');
$this->dataExchange();
time_nanosleep(0, 20000000);
}
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}