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

PHP flock函数代码示例

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

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



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

示例1: DeleteLyrics3

 function DeleteLyrics3()
 {
     // Initialize getID3 engine
     $getID3 = new getID3();
     $ThisFileInfo = $getID3->analyze($this->filename);
     if (isset($ThisFileInfo['lyrics3']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) {
         if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) {
             flock($fp, LOCK_EX);
             $oldignoreuserabort = ignore_user_abort(true);
             fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end'], SEEK_SET);
             $DataAfterLyrics3 = '';
             if ($ThisFileInfo['filesize'] > $ThisFileInfo['lyrics3']['tag_offset_end']) {
                 $DataAfterLyrics3 = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['lyrics3']['tag_offset_end']);
             }
             ftruncate($fp, $ThisFileInfo['lyrics3']['tag_offset_start']);
             if (!empty($DataAfterLyrics3)) {
                 fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start'], SEEK_SET);
                 fwrite($fp, $DataAfterLyrics3, strlen($DataAfterLyrics3));
             }
             flock($fp, LOCK_UN);
             fclose($fp);
             ignore_user_abort($oldignoreuserabort);
             return true;
         } else {
             $this->errors[] = 'Cannot fopen(' . $this->filename . ', "a+b")';
             return false;
         }
     }
     // no Lyrics3 present
     return true;
 }
开发者ID:ricofreak,项目名称:omekaArchiveProject,代码行数:31,代码来源:write.lyrics3.php


示例2: write_log

 /**
  * Write Log File
  *
  * Generally this function will be called using the global log_message() function
  *
  * @param    string    the error level
  * @param    string    the error message
  * @param    bool    whether the error is a native PHP error
  * @return    bool
  */
 public function write_log($level = 'error', $msg, $php_error = FALSE)
 {
     if ($this->_enabled === FALSE) {
         return FALSE;
     }
     $level = strtoupper($level);
     if (!isset($this->_levels[$level]) or $this->_levels[$level] > $this->_threshold) {
         return FALSE;
     }
     $filepath = $this->_log_path . 'log-' . date('Y-m-d') . '.php';
     $message = '';
     if (!file_exists($filepath)) {
         $message .= "<" . "?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?" . ">\n\n";
     }
     if (!($fp = @fopen($filepath, FOPEN_WRITE_CREATE))) {
         return FALSE;
     }
     $message .= $level . ' ' . ($level == 'INFO' ? ' -' : '-') . ' ' . date($this->_date_fmt) . ' --> ' . $msg . "\n";
     flock($fp, LOCK_EX);
     fwrite($fp, $message);
     flock($fp, LOCK_UN);
     fclose($fp);
     @chmod($filepath, FILE_WRITE_MODE);
     return TRUE;
 }
开发者ID:jorgemunoz8807,项目名称:admin_portal,代码行数:35,代码来源:Log.php


示例3: release

 /**
  * Free a lock acquired with acquire().
  *
  * @param resource $lockFile The lockfile that was returned by acquire()
  **/
 public static function release($lockFile)
 {
     if ($lockFile) {
         flock($lockFile, LOCK_UN);
         fclose($lockFile);
     }
 }
开发者ID:lyoshenka,项目名称:php-simple-lock,代码行数:12,代码来源:Lock.php


示例4: msg

 public function msg($msg)
 {
     if ($this->on && $this->handle && flock($this->handle, LOCK_EX)) {
         fputs($this->handle, date("[d/m/Y H:i:s] - ") . $msg . "\n");
         flock($this->handle, LOCK_UN);
     }
 }
开发者ID:vicb,项目名称:VisuGps,代码行数:7,代码来源:vg_log.php


示例5: ApiLogResult

/**
 * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
 * 注意:服务器需要开通fopen配置
 * @param $word 要写入日志里的文本内容 默认值:空值
 */
function ApiLogResult($word='') {
	$fp = fopen("log.txt","a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,"执行日期:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
开发者ID:8yong8,项目名称:vshop,代码行数:12,代码来源:core.function.php


示例6: call

 function call()
 {
     $args = func_get_args();
     $age = $args[0];
     $filename = $this->cachedir . base64_encode(join('', array_slice($args, 1))) . '.cache';
     $function = $args[1];
     if (file_exists($filename) && time() - filemtime($filename) < $age) {
         include $filename;
         print $output;
         return $return;
     }
     ob_start();
     $return = call_user_func_array($function, array_slice($args, 2));
     $output = ob_get_contents();
     ob_end_flush();
     $fp = fopen($filename, 'w');
     flock($fp, LOCK_EX);
     fwrite($fp, "<?php\r\n");
     if ($return != '') {
         fwrite($fp, '$return = <<<CACHEEOF' . "\r\n" . $return . "\r\nCACHEEOF;\r\n");
     }
     if ($output != '') {
         fwrite($fp, '$output = <<<CACHEEOF' . "\r\n" . $output . "\r\nCACHEEOF;\r\n");
     }
     fwrite($fp, "?>");
     flock($fp, LOCK_UN);
     fclose($fp);
     return $return;
 }
开发者ID:ranok,项目名称:wiki-wide-web,代码行数:29,代码来源:cache.lib.php


示例7: logger

 public static function logger($string)
 {
     $file = $this->root() . "log/sitesearch.log";
     // $file = "./log/sitesearch.log";
     // this is just for testing installation
     /*
      * if (!touch($file)) {
      * echo "FILE ERROR: cannot touch $file with user " . get_current_user() . "\n"; // helps figure out why you
      * can't touch the file
      * return;
      * } else {
      * echo "FILE: touched $file with user " . get_current_user() . "\n"; // helps figure out why you can't touch
      * the file
      * }
      */
     if (!($fh = fopen($file, 'a'))) {
         return;
     }
     flock($fh, LOCK_EX);
     $delim = "\t";
     date_default_timezone_set($conf['timeZone']);
     if (!fwrite($fh, 'StaticUtil[' . date('Y-M-d H:i:s') . ']' . $delim . $string . "\r\n")) {
         return;
     }
     flock($fh, LOCK_UN);
     fclose($fh);
 }
开发者ID:nickolanack,项目名称:geolive-bcmt-customexport,代码行数:27,代码来源:Util.php


示例8: save

 public function save($str)
 {
     if (!$this->logFilename) {
         return false;
     }
     $hash = md5($str);
     // if we've already logged this during this session, then don't do it again
     if (in_array($hash, $this->itemsLogged)) {
         return true;
     }
     $ts = date("Y-m-d H:i:s");
     $str = $this->cleanStr($str);
     if ($fp = fopen($this->logFilename, "a")) {
         $trys = 0;
         $stop = false;
         while (!$stop) {
             if (flock($fp, LOCK_EX)) {
                 fwrite($fp, "{$ts}{$this->delimeter}{$str}\n");
                 flock($fp, LOCK_UN);
                 $this->itemsLogged[] = $hash;
                 $stop = true;
             } else {
                 usleep(2000);
                 if ($trys++ > 20) {
                     $stop = true;
                 }
             }
         }
         fclose($fp);
         return true;
     } else {
         return false;
     }
 }
开发者ID:gusdecool,项目名称:bunga-wire,代码行数:34,代码来源:FileLog.php


示例9: rewrite

function rewrite($filename, $data)
{
    $filenum = fopen($filename, "w");
    flock($filenum, LOCK_EX);
    fwrite($filenum, $data);
    fclose($filenum);
}
开发者ID:armebayelm,项目名称:thinksns-vietnam,代码行数:7,代码来源:cleanbom.php


示例10: fhtml

function fhtml($txt, $html, $dir = "", $mu = "", $cahehtm)
{
    //$txt = file_get_contents($file);
    if ($dir != '') {
        $newdir = explode("/", $dir);
        $listdir = "";
        foreach ($newdir as $value) {
            $listdir .= "/{$value}";
            if (!is_dir(R_P . "html{$listdir}")) {
                mkdir(R_P . "html{$listdir}", 0777);
            }
        }
    }
    if ($mu != '') {
        $patterns = array("/(=)('|\"{0,1})(lang|image|attach|\\.)(\\/)(\\W?)(.*?)(\\W?)( |'|\"|>{1,2})/is");
        $replace = array("\\1\\2{$mu}\\3\\4\\5\\6\\7\\8");
        $txt = preg_replace($patterns, $replace, $txt);
    }
    if ($cahehtm) {
        P_unlink(R_P . $html);
    }
    $fp = fopen(R_P . $html, "w");
    flock($fp, LOCK_EX);
    fwrite($fp, $txt);
    fclose($fp);
    //关闭指针
    if (is_dir($mu) !== TRUE) {
        mkdir($mu, 0777);
    }
    chmod(R_P . $html, 0777);
}
开发者ID:holin,项目名称:sstour,代码行数:31,代码来源:html_fun.php


示例11: log

 /**
  * Logs a message.
  *
  * @param string Message
  * @param string Message priority
  * @param string Message priority name
  */
 public function log($message, $priority, $priorityName)
 {
     $line = sprintf("%s %s [%s] %s%s", strftime('%b %d %H:%M:%S'), 'symfony', $priorityName, $message, DIRECTORY_SEPARATOR == '\\' ? "\r\n" : "\n");
     flock($this->fp, LOCK_EX);
     fwrite($this->fp, $line);
     flock($this->fp, LOCK_UN);
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:14,代码来源:sfFileLogger.class.php


示例12: write

 /**
  * 实时写入日志
  * @param mixed $log
  * @param string $file
  */
 public static function write($log, $file = 'log')
 {
     $yearmonth = date('Ym');
     $logdir = ZTNB_ROOT . '/data/log/';
     $logfile = $logdir . $yearmonth . '_' . $file . '.php';
     if (@filesize($logfile) > 2048000) {
         $dir = opendir($logdir);
         $length = strlen($file);
         $maxid = $id = 0;
         while ($entry = readdir($dir)) {
             if (strpos($entry, $yearmonth . '_' . $file) !== false) {
                 $id = intval(substr($entry, $length + 8, -4));
                 $id > $maxid && ($maxid = $id);
             }
         }
         closedir($dir);
         $logfilebak = $logdir . $yearmonth . '_' . $file . '_' . ($maxid + 1) . '.php';
         @rename($logfile, $logfilebak);
     }
     if ($fp = @fopen($logfile, 'a')) {
         @flock($fp, 2);
         $log = var_export($log, true);
         $datetime = date('Y-m-d H:i:s');
         fwrite($fp, "<?PHP exit;?>\t{$datetime}\t" . str_replace(array('<?', '?>'), '', $log) . "\n");
         fclose($fp);
     }
 }
开发者ID:wsyandy,项目名称:zentao-rest-api,代码行数:32,代码来源:Logger.php


示例13: save

 function save($name, $data, $time = 86400)
 {
     //
     //We have problems if APC is enabled, so we disable our cache
     //system if it's lodoed to prevent those problems, but we will
     //try to fix it in the near future .. I hope that.
     //
     if (defined('APC_CACHE')) {
         return;
     }
     $name = preg_replace('![^a-z0-9_]!i', '_', $name);
     $data_for_save = '<?' . 'php' . "\n";
     $data_for_save .= '//Cache file, generated for Kleeja at ' . gmdate('d-m-Y h:i A') . "\n\n";
     $data_for_save .= '//No direct opening' . "\n";
     $data_for_save .= '(!defined("IN_COMMON") ? exit("hacking attemp!") : null);' . "\n\n";
     $data_for_save .= '//return false after x time' . "\n";
     $data_for_save .= 'if(time() > ' . (time() + $time) . ') return false;' . "\n\n";
     $data_for_save .= '$data = ' . var_export($data, true) . ";\n\n//end of cache";
     if ($fd = @fopen(PATH . 'cache/' . $name . '.php', 'w')) {
         @flock($fd, LOCK_EX);
         // exlusive look
         @fwrite($fd, $data_for_save);
         @flock($fd, LOCK_UN);
         @fclose($fd);
     }
     return;
 }
开发者ID:Amine12boutouil,项目名称:Kleeja-2.0.0-alpha,代码行数:27,代码来源:cache.php


示例14: create

 public function create($paths, $filename = FALSE)
 {
     // Sort the paths to make sure that directories come before files
     sort($paths);
     foreach ($paths as $set) {
         // Add each path individually
         $this->add_data($set[0], $set[1], isset($set[2]) ? $set[2] : NULL);
     }
     // File data
     $data = implode('', $this->data);
     // Directory data
     $dirs = implode('', $this->dirs);
     $zipfile = $data . $dirs . "PK" . pack('v', count($this->dirs)) . pack('v', count($this->dirs)) . pack('V', strlen($dirs)) . pack('V', strlen($data)) . "";
     // Zip comment length
     if ($filename == FALSE) {
         return $zipfile;
     }
     if (substr($filename, -3) != 'zip') {
         // Append zip extension
         $filename .= '.zip';
     }
     // Create the file in binary write mode
     $file = fopen($filename, 'wb');
     // Lock the file
     flock($file, LOCK_EX);
     // Write the zip file
     $return = fwrite($file, $zipfile);
     // Unlock the file
     flock($file, LOCK_UN);
     // Close the file
     fclose($file);
     return (bool) $return;
 }
开发者ID:BRMatt,项目名称:kohana-archive,代码行数:33,代码来源:zip.php


示例15: readFromStdin

 /**
  * readFromStdin($prompt = 'Enter: ', $echoback = false)
  *
  * 標準入力からの入力を処理する
  *
  * @access    protected
  *
  * @param     string  $message ブラウザ側に出力するメッセージ(省略可、デフォルトは'Authorization Required')
  * @param     boolean $echoback true:エコーバックする/false:エコーバックしない
  *
  * @return    string 入力された内容
  */
 protected function readFromStdin($prompt = 'Enter: ', $echoback = true)
 {
     // 入出力のファイルハンドラをオープン
     $in = fopen('php://stdin', 'r');
     $out = fopen('php://stderr', 'w');
     // プロンプトを出力し、エコーバックオフが指示されていれば止める
     fwrite($out, $prompt);
     if (!$echoback) {
         system('stty -echo');
     }
     // 入力をロックし、キー入力を取得する
     flock($in, LOCK_EX);
     $readtext = fgets($in);
     flock($in, LOCK_UN);
     // エコーバックオフが指示されていれば再開し、PHP_EOLを出力
     if (!$echoback) {
         system('stty echo');
     }
     fwrite($out, PHP_EOL);
     // 入出力のファイルハンドラをクローズ
     fclose($in);
     fclose($out);
     // 取得内容を返却する
     return trim($readtext);
 }
开发者ID:risoluto,项目名称:risoluto-core,代码行数:37,代码来源:RisolutoCliBase.php


示例16: doFetch

 /**
  * {@inheritdoc}
  */
 protected function doFetch(array $ids)
 {
     $values = array();
     $now = time();
     foreach ($ids as $id) {
         $file = $this->getFile($id);
         if (!($h = @fopen($file, 'rb'))) {
             continue;
         }
         flock($h, LOCK_SH);
         if ($now >= (int) ($expiresAt = fgets($h))) {
             flock($h, LOCK_UN);
             fclose($h);
             if (isset($expiresAt[0])) {
                 @unlink($file);
             }
         } else {
             $value = stream_get_contents($h);
             flock($h, LOCK_UN);
             fclose($h);
             $values[$id] = unserialize($value);
         }
     }
     return $values;
 }
开发者ID:Amo,项目名称:symfony,代码行数:28,代码来源:FilesystemAdapter.php


示例17: read

 /**
  * read and get cache file
  * 
  * @param string
  * @return html
  */
 function read($filename)
 {
     $filename = md5($filename);
     $filepath = $this->getConfig('cache_path') . $filename . '.tmp';
     if (!file_exists($filepath)) {
         return FALSE;
     }
     if (!($fp = @fopen($filepath, 'r'))) {
         return FALSE;
     }
     flock($fp, LOCK_SH);
     $cache = '';
     if (filesize($filepath) > 0) {
         $cache = fread($fp, filesize($filepath));
     }
     flock($fp, LOCK_UN);
     fclose($fp);
     // Strip out the embedded timestamp
     if (!preg_match("/(\\d+T_SKY-->)/", $cache, $match)) {
         return FALSE;
     }
     // Has the file expired? If so we'll delete it.
     if (time() >= trim(str_replace('TS--->', '', $match['1']))) {
         if (is_writable($filepath)) {
             @unlink($filepath);
             return FALSE;
         }
     }
     // Display the cache
     return str_replace($match['0'], '', $cache);
 }
开发者ID:Rockbeat-Sky,项目名称:framework,代码行数:37,代码来源:Cache.php


示例18: getContent

 /**
  * Create content from template and data.
  *
  * @param string $name
  * @param array $data
  *
  * @return string|null
  */
 public function getContent($name, array $data = [])
 {
     $path = $this->packageRoot . '/view/_cache/' . str_replace('/', '_', $name);
     if (!file_exists($path) || !$this->cache) {
         $code = $this->compile($name, true, true);
         if (empty($code)) {
             return null;
         }
         $fh = fopen($path, 'wb');
         if (flock($fh, LOCK_EX)) {
             fwrite($fh, $code);
             flock($fh, LOCK_UN);
         }
         fflush($fh);
         fclose($fh);
     }
     $fh = fopen($path, 'rb');
     flock($fh, LOCK_SH);
     if (null !== $this->request) {
         $data = array_replace($data, ['request' => $this->request]);
     }
     $html = self::renderTemplate($path, $data);
     flock($fh, LOCK_UN);
     fclose($fh);
     return $html;
 }
开发者ID:dspbee,项目名称:pivasic,代码行数:34,代码来源:Native.php


示例19: getActualCache

function getActualCache($cacheFile, $cacheAgeLimit, $source)
{
    $fMakeTemplateCache = false;
    if (is_file($cacheFile)) {
        $filetime = filemtime($cacheFile);
        $curtime = time();
        $cacheFilenameAge = $curtime - $filetime;
        //print $cacheFilenameAge;
        if ($cacheFilenameAge > $cacheAgeLimit) {
            $fMakeTemplateCache = true;
        }
    } else {
        $fMakeTemplateCache = true;
    }
    if ($fMakeTemplateCache) {
        //print "Write new cache";
        // Write new cache
        $cacheContent = file_get_contents($source);
        // Открытие текстовых файлов
        $fhCache = fopen($cacheFile, "w");
        $locked = flock($fhCache, LOCK_EX | LOCK_NB);
        if (!$locked) {
            echo 'Не удалось получить блокировку';
            exit(-1);
        }
        fwrite($fhCache, $cacheContent);
    } else {
        //print "Read from cache";
        // Read from cache
        $cacheContent = file_get_contents($cacheFile);
    }
    // Output template
    return $cacheContent;
}
开发者ID:knowall,项目名称:Trap_for_hacker,代码行数:34,代码来源:getactualcache.php


示例20: export

 public function export($location)
 {
     if (file_exists($location) === false) {
         mkdir($location);
     }
     if (substr($location, -1) != DIRECTORY_SEPARATOR) {
         $location .= DIRECTORY_SEPARATOR;
     }
     $file = $location . $this->_group_name . EXT;
     // Write in file
     if (!($h = fopen($file, 'w+'))) {
         return FALSE;
     }
     // Block access to the file
     if (flock($h, LOCK_EX)) {
         $array = $this->getArrayCopy();
         // Modifiers for adjusting appearance
         $replace = array("=> \n" => '=>', 'array (' => 'array(', '  ' => "\t", ' false,' => ' FALSE,', ' true,' => ' TRUE,', ' null,' => ' NULL,', MODPATH => 'MODPATH', APPPATH => 'APPPATH', SYSPATH => 'SYSPATH', DOCROOT => 'DOCROOT');
         $array = var_export($array, true);
         $var = stripslashes(strtr($array, $replace));
         $content = Kohana::FILE_SECURITY . PHP_EOL . PHP_EOL . 'return ' . $var . ';';
         $result = fwrite($h, $content);
         flock($h, LOCK_UN);
     }
     fclose($h);
     return (bool) $result;
 }
开发者ID:happydemon,项目名称:arr,代码行数:27,代码来源:Group.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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