本文整理汇总了PHP中sleep函数的典型用法代码示例。如果您正苦于以下问题:PHP sleep函数的具体用法?PHP sleep怎么用?PHP sleep使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sleep函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendData
protected static function sendData($host, $POST, $HEAD, $filepath, $mediafile, $TAIL)
{
$sock = fsockopen("ssl://" . $host, 443);
fwrite($sock, $POST);
fwrite($sock, $HEAD);
//write file data
$buf = 1024;
$totalread = 0;
$fp = fopen($filepath, "r");
while ($totalread < $mediafile['filesize']) {
$buff = fread($fp, $buf);
fwrite($sock, $buff, $buf);
$totalread += $buf;
}
//echo $TAIL;
fwrite($sock, $TAIL);
sleep(1);
$data = fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
fclose($sock);
list($header, $body) = preg_split("/\\R\\R/", $data, 2);
$json = json_decode($body);
if (!is_null($json)) {
return $json;
}
return false;
}
示例2: connect
function connect($server, $db, $user, $password, $socketPath, $charset = null, $port = false)
{
$connection = false;
if ($socketPath !== false) {
ini_set("mysqli.default_socket", $socketPath);
}
if ($this->UsePersistentConnection == true) {
// Only supported on PHP 5.3 (mysqlnd)
if (version_compare(PHP_VERSION, '5.3') > 0) {
$this->Server = 'p:' . $this->Server;
} else {
eZDebug::writeWarning('mysqli only supports persistent connections when using php 5.3 and higher', 'eZMySQLiDB::connect');
}
}
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$connection = mysqli_connect($server, $user, $password, null, (int) $port, $socketPath);
$dbErrorText = mysqli_connect_error();
eZPerfLogger::accumulatorStop('mysqli_connection');
$maxAttempts = $this->connectRetryCount();
$waitTime = $this->connectRetryWaitTime();
$numAttempts = 1;
while (!$connection && $numAttempts <= $maxAttempts) {
sleep($waitTime);
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$connection = mysqli_connect($this->Server, $this->User, $this->Password, null, (int) $this->Port, $this->SocketPath);
eZPerfLogger::accumulatorStop('mysqli_connection');
$numAttempts++;
}
$this->setError();
$this->IsConnected = true;
if (!$connection) {
eZDebug::writeError("Connection error: Couldn't connect to database. Please try again later or inform the system administrator.\n{$dbErrorText}", __CLASS__);
$this->IsConnected = false;
throw new eZDBNoConnectionException($server);
}
if ($this->IsConnected && $db != null) {
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$ret = mysqli_select_db($connection, $db);
eZPerfLogger::accumulatorStop('mysqli_connection');
if (!$ret) {
//$this->setError();
eZDebug::writeError("Connection error: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
$this->IsConnected = false;
}
}
if ($charset !== null) {
$originalCharset = $charset;
$charset = eZCharsetInfo::realCharsetCode($charset);
}
if ($this->IsConnected and $charset !== null) {
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$status = mysqli_set_charset($connection, eZMySQLCharset::mapTo($charset));
eZPerfLogger::accumulatorStop('mysqli_connection');
if (!$status) {
$this->setError();
eZDebug::writeWarning("Connection warning: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
}
}
return $connection;
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
$oldCacheDir = $realCacheDir . '_old';
$filesystem = $this->getContainer()->get('filesystem');
if (!is_writable($realCacheDir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
}
if ($filesystem->exists($oldCacheDir)) {
$filesystem->remove($oldCacheDir);
}
$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
if ($input->getOption('no-warmup')) {
$filesystem->rename($realCacheDir, $oldCacheDir);
} else {
// the warmup cache dir name must have the same length than the real one
// to avoid the many problems in serialized resources files
$warmupDir = substr($realCacheDir, 0, -1) . '_';
if ($filesystem->exists($warmupDir)) {
$filesystem->remove($warmupDir);
}
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
$filesystem->rename($realCacheDir, $oldCacheDir);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
sleep(1);
// workaround for windows php rename bug
}
$filesystem->rename($warmupDir, $realCacheDir);
}
$filesystem->remove($oldCacheDir);
}
示例4: queueSend
/**
* 通知客户端
* Enter description here ...
* @param unknown_type $operation
* @param unknown_type $data
*/
protected function queueSend($start = 0)
{
$time = Windid::getTime();
$appids = $nids = array();
$logDs = $this->_getNotifyLogDs();
$queue = $logDs->getList(0, 0, 10, $start, 0);
if (!$queue) {
return false;
}
foreach ($queue as $v) {
$appids[] = $v['appid'];
$nids[] = $v['nid'];
}
$apps = $this->_getAppDs()->fetchApp(array_unique($appids));
$notifys = $this->_getNotifyDs()->fetchNotify(array_unique($nids));
$postData = $urls = array();
foreach ($queue as $k => $v) {
$appid = $v['appid'];
$nid = $v['nid'];
$array = array('windidkey' => WindidUtility::appKey($v['appid'], $time, $apps[$appid]['secretkey']), 'operation' => $notifys[$nid]['operation'], 'uid' => (int) $notifys[$nid]['param'], 'clientid' => $v['appid'], 'time' => $time);
$urls[$k] = WindidUtility::buildClientUrl($apps[$appid]['siteurl'], $apps[$appid]['apifile']) . http_build_query($array);
}
if (!$urls) {
return false;
}
$result = WindidUtility::buildMultiRequest($urls);
sleep(3);
$this->logId = $this->logId + $result;
$start += 10;
$this->queueSend($start);
}
示例5: cron_verifyTiezi
function cron_verifyTiezi()
{
global $m;
$set = unserialize(option::get('plugin_verifyTiezi'));
$today = date("Y-m-d");
//准备:扫描verifyTiezi表中lastdo不是今天的,然后更新verifyTiezi_data表的remain
$sy = $m->query("SELECT * FROM `" . DB_PREFIX . "verifyTiezi` WHERE `lastdo` != '{$today}';");
while ($sx = $m->fetch_array($sy)) {
$m->query('UPDATE `' . DB_NAME . '`.`' . DB_PREFIX . 'verifyTiezi_data` SET `remain` = \'' . $sx['num'] . '\' WHERE `uid` = ' . $sx['uid']);
$m->query('UPDATE `' . DB_NAME . '`.`' . DB_PREFIX . 'verifyTiezi` SET `lastdo` = \'' . $today . '\' WHERE `uid` = ' . $sx['uid']);
}
//开始:计划任务
$count = $m->once_fetch_array("SELECT COUNT(*) AS `c` FROM `" . DB_PREFIX . "verifyTiezi_data` WHERE `remain` > '0' LIMIT {$set['rem']};");
if ($count['c'] == $set['rem']) {
$y = rand_row(DB_PREFIX . 'verifyTiezi_data', 'id', $set['rem'], "`remain` > '0'");
} else {
$y = rand_row(DB_PREFIX . 'verifyTiezi_data', 'id', $count['c'], "`remain` > '0'");
}
//如果只有一条记录的兼容方案
if (isset($y['url'])) {
$y = array(0 => $y);
}
foreach ($y as $x) {
if (!empty($x['pid']) && !empty($x['uid'])) {
$u = $m->once_fetch_array("SELECT * FROM `" . DB_PREFIX . "verifyTiezi` WHERE `uid` = '{$x['uid']}'");
$cont = unserialize($u['cont']);
$remain = $x['remain'] - 1;
$res = verifyTiezi_send($x['uid'], $x['url'], $x['pid'], rand_array($cont), $set['device']);
$m->query('UPDATE `' . DB_NAME . '`.`' . DB_PREFIX . 'verifyTiezi_data` SET `remain` = \'' . $remain . '\',`status` = \'' . $res['status'] . '\',`msg` = \'' . $res['msg'] . '\' WHERE `url` = \'' . $x['url'] . '\' AND `uid` = ' . $x['uid']);
sleep($set['sleep']);
}
}
}
示例6: confirm
function confirm($seconds)
{
sleep($seconds);
$objResponse = new xajaxResponse();
$objResponse->append('outputDIV', 'innerHTML', '<br />confirmation from theFrame.php call');
return $objResponse;
}
示例7: testGenerateTimestamp
public function testGenerateTimestamp()
{
$idA = \Simpleflake\generate(null, 0, 0);
sleep(1);
$idB = \Simpleflake\generate(null, 0, 0);
$this->assertNotEquals($idA, $idB);
}
示例8: get_profile_email
function get_profile_email($url)
{
global $g_acegi_cookie;
global $g_session_cookie;
global $g_delay;
sleep($g_delay);
// Create a stream
// get cookie values using wget commands
$cookie = sprintf("Cookie: ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE=%s; JSESSIONID=%s\r\n", $g_acegi_cookie, $g_session_cookie);
$opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n" . $cookie));
$context = stream_context_create($opts);
@($html = file_get_contents($url, false, $context));
$doc = new \DOMDocument();
@$doc->loadHTML($html);
$emailNode = $doc->getElementById("email1__ID__");
$nameNode = $doc->getElementById("name1__ID__");
$titleNode = $doc->getElementById("title1__ID__");
$companyNode = $doc->getElementById("company1__ID__");
if (!is_null($emailNode)) {
$data = array();
$data["email"] = $emailNode->nodeValue;
$data["name"] = is_null($nameNode) ? "" : $nameNode->nodeValue;
$data["title"] = is_null($titleNode) ? "" : $titleNode->nodeValue;
$data["company"] = is_null($companyNode) ? "" : $companyNode->nodeValue;
return $data;
}
return NULL;
}
示例9: testNoExpire
public function testNoExpire()
{
$cache = $this->_getCacheDriver();
$cache->save('noexpire', 'value', 0);
sleep(1);
$this->assertTrue($cache->contains('noexpire'), 'Couchbase provider should support no-expire');
}
示例10: get
/**
* A proxy curl implementation to get the content of the url.
*
* @param string $url
*
* @return string
* @throws CurlException
*/
public function get($url)
{
$ch = curl_init($url);
if (!ini_get('open_basedir')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
}
if (self::$proxy) {
curl_setopt($ch, CURLOPT_PROXY, self::$proxy);
}
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);
curl_setopt($ch, CURLOPT_REFERER, $this->getReferrer());
/*curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);*/
sleep(mt_rand(10, 20));
$content = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->connectedURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
if (404 === $code) {
throw new CurlException('Content not found.');
}
if ($content === false) {
// there was a problem
$error = curl_error($ch);
throw new CurlException('Error retrieving "' . $url . '" (' . $error . ')');
}
if (false !== strpos($content, 'Error 525')) {
throw new CurlException('Error in a source site.');
}
return $content;
}
示例11: exec_curl_request
function exec_curl_request($handle)
{
$response = curl_exec($handle);
if ($response === false) {
$errno = curl_errno($handle);
$error = curl_error($handle);
error_log("Curl retornou um erro {$errno}: {$error}\n");
curl_close($handle);
return false;
}
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
curl_close($handle);
if ($http_code >= 500) {
// do not wat to DDOS server if something goes wrong
sleep(10);
return false;
} else {
if ($http_code != 200) {
$response = json_decode($response, true);
error_log("Request has failed with error {$response['error_code']}: {$response['description']}\n");
if ($http_code == 401) {
throw new Exception('Invalid access token provided');
}
return false;
} else {
$response = json_decode($response, true);
if (isset($response['description'])) {
error_log("Request was successfull: {$response['description']}\n");
}
$response = $response['result'];
}
}
return $response;
}
示例12: testAutomatedCron
/**
* Ensure that the automated cron run module is working.
*
* In these tests we do not use REQUEST_TIME to track start time, because we
* need the exact time when cron is triggered.
*/
function testAutomatedCron()
{
// Test with a logged in user; anonymous users likely don't cause Drupal to
// fully bootstrap, because of the internal page cache or an external
// reverse proxy. Reuse this user for disabling cron later in the test.
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
// Ensure cron does not run when a non-zero cron interval is specified and
// was not passed.
$cron_last = time();
$cron_safe_interval = 100;
\Drupal::state()->set('system.cron_last', $cron_last);
$this->config('automated_cron.settings')->set('interval', $cron_safe_interval)->save();
$this->drupalGet('');
$this->assertTrue($cron_last == \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron interval is not passed.');
// Test if cron runs when the cron interval was passed.
$cron_last = time() - 200;
\Drupal::state()->set('system.cron_last', $cron_last);
$this->drupalGet('');
sleep(1);
$this->assertTrue($cron_last < \Drupal::state()->get('system.cron_last'), 'Cron runs when the cron interval is passed.');
// Disable cron through the interface by setting the interval to zero.
$this->drupalPostForm('admin/config/system/cron', ['interval' => 0], t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$this->drupalLogout();
// Test if cron does not run when the cron interval is set to zero.
$cron_last = time() - 200;
\Drupal::state()->set('system.cron_last', $cron_last);
$this->drupalGet('');
$this->assertTrue($cron_last == \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron threshold is disabled.');
}
示例13: itemSealAction
public function itemSealAction()
{
$LogType = $this->request->LogType;
if ($LogType) {
do {
$S = time();
$AppId = intval($this->request->AppId);
if ($AppId) {
$ItemSeal = array();
$SealItem = $this->oSeal->getAll($AppId);
foreach ($SealItem as $k => $v) {
$ItemIds[$v['SealTimeType']][$v['SealTime']][$v['AppId']][] = $v['ItemId'];
$ItemSeal[$v['ItemId']]['ItemSeal'] = $v['ItemSeal'];
$ItemSeal[$v['ItemId']]['ItemName'] = $v['ItemName'];
}
foreach ($ItemIds as $k => $v) {
switch ($k) {
case "hh":
$this->checkSeal($v, "Y-m-d H:00:00", 3600, $ItemSeal, $LogType, $k);
break;
case "dd":
$this->checkSeal($v, "Y-m-d 00:00:00", 86400, $ItemSeal, $LogType, $k);
break;
}
}
}
$E = time();
if ($E - $S < 900) {
sleep(900 - ($E - $S));
}
} while (true);
}
}
示例14: downloadAction
public function downloadAction()
{
$squadID = $this->params('id', 0);
$squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad');
/** @var Squad $squadEntity */
$squadEntity = $squadRepo->findOneBy(array('user' => $this->identity(), 'id' => $squadID));
if (!$squadEntity) {
$this->flashMessenger()->addErrorMessage('Squad not found');
return $this->redirect('frontend/user/squads');
}
$fileName = 'squad_file_pack_armasquads_' . $squadID;
$zipTmpPath = tempnam(ini_get('upload_tmp_dir'), $fileName);
$zip = new \ZipArchive();
$zip->open($zipTmpPath, \ZipArchive::CHECKCONS);
if (!$zip) {
$this->flashMessenger()->addErrorMessage('Squad Package Download currently not possible');
return $this->redirect('frontend/user/squads');
}
$zip->addFromString('squad.xml', file_get_contents('http://' . $_SERVER['SERVER_NAME'] . $this->url()->fromRoute('frontend/user/squads/xml', array('id' => $squadEntity->getPrivateID()))));
if ($squadEntity->getSquadLogoPaa()) {
$zip->addFile(ROOT_PATH . $squadEntity->getSquadLogoPaa(), basename($squadEntity->getSquadLogoPaa()));
}
$zip->addFromString('squad.dtd', file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/') . '/squad.dtd'));
//$zip->addFromString('squad.xsl',file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/').'/squad.xsl'));
$zip->close();
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($fileName) . ".zip\"");
readfile($zipTmpPath);
sleep(1);
@unlink($zipTmpPath);
die;
}
示例15: testMoveTaskAnotherSwimlane
public function testMoveTaskAnotherSwimlane()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
$p = new Project($this->container);
$tf = new TaskFinder($this->container);
$s = new Swimlane($this->container);
$this->container['dispatcher'] = new EventDispatcher();
$this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container));
$now = time();
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals($now, $task['date_moved'], '', 1);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(0, $task['swimlane_id']);
sleep(1);
$this->assertTrue($tp->movePosition(1, 1, 2, 1, 2));
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertNotEquals($now, $task['date_moved']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['swimlane_id']);
}