当前位置: 首页>>代码示例>>PHP>>正文


PHP flock函数代码示例

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


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


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