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


PHP set_file_buffer函数代码示例

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


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

示例1: add

 public function add($csvRow)
 {
     $lock = fopen("../storage/waitlists/update.lock", "r");
     if (flock($lock, LOCK_SH)) {
         if (!file_exists($this->filePath)) {
             $entry = "Course,Section,First Name,Last Name,Email,Student ID,Reason" . $csvRow;
         } else {
             $entry = $csvRow;
         }
         $fp = fopen($this->filePath, 'a');
         chmod($this->filePath, 0600);
         // lock file for write
         if (flock($fp, LOCK_EX)) {
             // write entire line before releasing lock
             set_file_buffer($fp, 0);
             fwrite($fp, $entry);
             flock($fp, LOCK_UN);
         } else {
             error_log("could not obtain lock for " . $this->department . " file.");
         }
         fclose($fp);
     } else {
         error_log("Could not add to waitlists");
     }
     flock($lock, LOCK_UN);
     fclose($lock);
 }
开发者ID:ayejeyess,项目名称:scu-waitlist,代码行数:27,代码来源:Waitlist.php

示例2: plugin_counter_get_count

function plugin_counter_get_count($page)
{
    global $vars;
    static $counters = array();
    static $default;
    if (!isset($default)) {
        $default = array('total' => 0, 'date' => get_date('Y/m/d'), 'today' => 0, 'yesterday' => 0, 'ip' => '');
    }
    if (!is_page($page)) {
        return $default;
    }
    if (isset($counters[$page])) {
        return $counters[$page];
    }
    // Set default
    $counters[$page] = $default;
    $modify = FALSE;
    $file = COUNTER_DIR . encode($page) . PLUGIN_COUNTER_SUFFIX;
    $fp = fopen($file, file_exists($file) ? 'r+' : 'w+') or die('counter.inc.php: Cannot open COUTER_DIR/' . basename($file));
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    rewind($fp);
    foreach ($default as $key => $val) {
        // Update
        $counters[$page][$key] = rtrim(fgets($fp, 256));
        if (feof($fp)) {
            break;
        }
    }
    if ($counters[$page]['date'] != $default['date']) {
        // New day
        $modify = TRUE;
        $is_yesterday = $counters[$page]['date'] == get_date('Y/m/d', strtotime('yesterday', UTIME));
        $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
        $counters[$page]['date'] = $default['date'];
        $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0;
        $counters[$page]['today'] = 1;
        $counters[$page]['total']++;
    } else {
        if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR']) {
            // Not the same host
            $modify = TRUE;
            $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
            $counters[$page]['today']++;
            $counters[$page]['total']++;
        }
    }
    // Modify
    if ($modify && $vars['cmd'] == 'read') {
        rewind($fp);
        ftruncate($fp, 0);
        foreach (array_keys($default) as $key) {
            fputs($fp, $counters[$page][$key] . "\n");
        }
    }
    flock($fp, LOCK_UN);
    fclose($fp);
    return $counters[$page];
}
开发者ID:geoemon2k,项目名称:source_wiki,代码行数:59,代码来源:counter.inc.php

示例3: ref_save

function ref_save($page)
{
    global $referer, $use_spam_check;
    // if (PKWK_READONLY || ! $referer || empty($_SERVER['HTTP_REFERER'])) return TRUE;
    // if (auth::check_role('readonly') || ! $referer || empty($_SERVER['HTTP_REFERER'])) return TRUE;
    if (!$referer || empty($_SERVER['HTTP_REFERER'])) {
        return TRUE;
    }
    $url = $_SERVER['HTTP_REFERER'];
    // Validate URI (Ignore own)
    $parse_url = parse_url($url);
    if ($parse_url === FALSE || !isset($parse_url['host']) || $parse_url['host'] == $_SERVER['HTTP_HOST']) {
        return TRUE;
    }
    // Blocking SPAM
    if ($use_spam_check['referer'] && SpamCheck($parse_url['host'])) {
        return TRUE;
    }
    if (!is_dir(REFERER_DIR)) {
        die('No such directory: REFERER_DIR');
    }
    if (!is_writable(REFERER_DIR)) {
        die('Permission denied to write: REFERER_DIR');
    }
    // Update referer data
    if (ereg("[,\"\n\r]", $url)) {
        $url = '"' . str_replace('"', '""', $url) . '"';
    }
    $data = ref_get_data($page, 3);
    $d_url = rawurldecode($url);
    if (!isset($data[$d_url])) {
        $data[$d_url] = array('', UTIME, 0, $url, 1);
    }
    $data[$d_url][0] = UTIME;
    $data[$d_url][2]++;
    $filename = ref_get_filename($page);
    $fp = fopen($filename, 'w');
    if ($fp === FALSE) {
        return FALSE;
    }
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    rewind($fp);
    foreach ($data as $line) {
        $str = trim(join(',', $line));
        if ($str != '') {
            fwrite($fp, $str . "\n");
        }
    }
    @flock($fp, LOCK_UN);
    fclose($fp);
    return TRUE;
}
开发者ID:aterai,项目名称:pukiwiki-plus-i18n,代码行数:53,代码来源:referer.php

示例4: nel_write_file

function nel_write_file($filename, $output, $chmod)
{
    $fp = fopen($filename, "w");
    if (!$fp) {
        echo 'Failed to open file for writing. Check permissions.';
        return FALSE;
    }
    set_file_buffer($fp, 0);
    rewind($fp);
    fputs($fp, $output);
    fclose($fp);
    chmod($filename, $chmod);
    return TRUE;
}
开发者ID:OtakuMegane,项目名称:Nelliel,代码行数:14,代码来源:file-handling.php

示例5: get_ticket

function get_ticket($newticket = FALSE)
{
    $file = CACHE_DIR . 'ticket.dat';
    if (file_exists($file) && $newticket !== TRUE) {
        $fp = fopen($file, 'r') or die_message('Cannot open ' . 'CACHE_DIR/' . 'ticket.dat');
        $ticket = trim(fread($fp, filesize($file)));
        fclose($fp);
    } else {
        $ticket = md5(mt_rand());
        pkwk_touch_file($file);
        $fp = fopen($file, 'r+') or die_message('Cannot open ' . 'CACHE_DIR/' . 'ticket.dat');
        set_file_buffer($fp, 0);
        @flock($fp, LOCK_EX);
        $last = ignore_user_abort(1);
        ftruncate($fp, 0);
        rewind($fp);
        fputs($fp, $ticket . "\n");
        ignore_user_abort($last);
        @flock($fp, LOCK_UN);
        fclose($fp);
    }
    return $ticket;
}
开发者ID:orangeal2o3,项目名称:pukiwiki-plugin,代码行数:23,代码来源:fileplus.php

示例6: plugin_tb_save

function plugin_tb_save($url, $tb_id)
{
    global $vars, $trackback, $use_spam_check;
    static $fields = array('url', 'title', 'excerpt', 'blog_name');
    $die = '';
    if (!$trackback) {
        $die .= 'TrackBack feature disabled. ';
    }
    if ($url == '') {
        $die .= 'URL parameter is not set. ';
    }
    if ($tb_id == '') {
        $die .= 'TrackBack Ping ID is not set. ';
    }
    if ($die != '') {
        plugin_tb_return(PLUGIN_TB_ERROR, $die);
    }
    if (!file_exists(TRACKBACK_DIR)) {
        plugin_tb_return(PLUGIN_TB_ERROR, 'No such directory: TRACKBACK_DIR');
    }
    if (!is_writable(TRACKBACK_DIR)) {
        plugin_tb_return(PLUGIN_TB_ERROR, 'Permission denied: TRACKBACK_DIR');
    }
    $page = tb_id2page($tb_id);
    if ($page === FALSE) {
        plugin_tb_return(PLUGIN_TB_ERROR, 'TrackBack ID is invalid.');
    }
    // URL validation (maybe worse of processing time limit)
    if (!is_url($url)) {
        plugin_tb_return(PLUGIN_TB_ERROR, 'URL is fictitious.');
    }
    if (PLUGIN_TB_SITE_CHECK === TRUE) {
        $result = http_request($url);
        if ($result['rc'] !== 200) {
            plugin_tb_return(PLUGIN_TB_ERROR, 'URL is fictitious.');
        }
        $urlbase = get_script_absuri();
        $matches = array();
        if (preg_match_all('#' . preg_quote($urlbase, '#') . '#i', $result['data'], $matches) == 0) {
            honeypot_write();
            if (PLUGIN_TB_HTTP_ERROR === TRUE && is_sapi_clicgi() === FALSE) {
                header('HTTP/1.0 403 Forbidden');
                exit;
            }
            plugin_tb_return(PLUGIN_TB_ERROR, 'Writing is prohibited.');
        }
    } else {
        $result = http_request($url, 'HEAD');
        if ($result['rc'] !== 200) {
            plugin_tb_return(PLUGIN_TB_ERROR, 'URL is fictitious.');
        }
    }
    // Update TrackBack Ping data
    $filename = tb_get_filename($page);
    $data = tb_get($filename);
    $matches = array();
    $items = array(UTIME);
    foreach ($fields as $key) {
        $value = isset($vars[$key]) ? $vars[$key] : '';
        if (preg_match('/[,"' . "\n\r" . ']/', $value)) {
            $value = '"' . str_replace('"', '""', $value) . '"';
        }
        $items[$key] = $value;
        // minimum checking from SPAM
        if (preg_match_all('/a\\s+href=/i', $items[$key], $matches) >= 1) {
            honeypot_write();
            if (PLUGIN_TB_HTTP_ERROR === TRUE && is_sapi_clicgi() === FALSE) {
                header('HTTP/1.0 400 Bad Request');
                exit;
            }
            plugin_tb_return(PLUGIN_TB_ERROR, 'Writing is prohibited.');
        }
    }
    // minimum checking from SPAM #2
    foreach (array('title', 'excerpt', 'blog_name') as $key) {
        if (preg_match_all('#http\\://#i', $items[$key], $matches) >= 1) {
            honeypot_write();
            if (PLUGIN_TB_HTTP_ERROR === TRUE && is_sapi_clicgi() === FALSE) {
                header('HTTP/1.0 400 Bad Request');
                exit;
            }
            plugin_tb_return(PLUGIN_TB_ERROR, 'Writing is prohibited.');
        }
    }
    // Blocking SPAM
    if ($use_spam_check['trackback'] && SpamCheck($items['url'])) {
        plugin_tb_return(1, 'Writing is prohibited.');
    }
    $data[rawurldecode($items['url'])] = $items;
    $fp = fopen($filename, 'w');
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    rewind($fp);
    foreach ($data as $line) {
        $line = preg_replace('/[\\r\\n]/s', '', $line);
        // One line, one ping
        fwrite($fp, join(',', $line) . "\n");
    }
    flock($fp, LOCK_UN);
    fclose($fp);
//.........这里部分代码省略.........
开发者ID:aterai,项目名称:pukiwiki-plus-i18n,代码行数:101,代码来源:tb.inc.php

示例7: file_head

 /**
  * Reads heads of file into an array
  *
  * PHP API Extension
  *
  * @access public
  * @static
  * @param string  $file filename
  * @param int     $count number of executed fgets, usually equivalent to number of lines
  * @param boolean $lock use lock or not 
  * @param int     $buffer number of bytes to be read in one fgets
  * @return array
  * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $
  */
 function file_head($file, $count = 1, $lock = true, $buffer = 8192)
 {
     $array = array();
     $fp = @fopen($file, 'r');
     if ($fp === false) {
         return false;
     }
     set_file_buffer($fp, 0);
     if ($lock) {
         @flock($fp, LOCK_SH);
     }
     rewind($fp);
     $index = 0;
     while (!feof($fp)) {
         $line = fgets($fp, $buffer);
         if ($line != false) {
             $array[] = $line;
         }
         if (++$index >= $count) {
             break;
         }
     }
     if ($lock) {
         @flock($fp, LOCK_UN);
     }
     if (!fclose($fp)) {
         return false;
     }
     return $array;
 }
开发者ID:orangeal2o3,项目名称:pukiwiki-plugin,代码行数:44,代码来源:sonots.class.php

示例8: fopen

            $domains[] = $parts[$i];
        }
    }
}
// Load previous results
$fp = fopen('testsuite.txt', 'rt');
if (!$fp) {
    $results = array();
} else {
    $results = unserialize(fgets($fp));
    fclose($fp);
}
// Test domains
include 'whois.main.php';
$whois = new Whois();
set_file_buffer(STDIN, 0);
foreach ($domains as $key => $domain) {
    echo "\nTesting {$domain} ---------------------------------\n";
    $result = $whois->Lookup($domain);
    unset($result['rawdata']);
    if (!isset($results[$domain])) {
        print_r($result);
        $res = get_answer("Add result for {$domain}");
        if ($res) {
            // Add as it is
            unset($result['regrinfo']['disclaimer']);
            $results[$domain] = $result;
        }
    } else {
        // Compare with previous result
        unset($result['regrinfo']['disclaimer']);
开发者ID:carriercomm,项目名称:NeoBill,代码行数:31,代码来源:testsuite.php

示例9: tb_get

function tb_get($file, $key = 1)
{
    if (!file_exists($file)) {
        return array();
    }
    $result = array();
    $fp = @fopen($file, 'r');
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    rewind($fp);
    while ($data = @fgets($fp, 8192)) {
        // $data[$key] = URL
        $data = csv_explode(',', $data);
        $result[rawurldecode($data[$key])] = $data;
    }
    @flock($fp, LOCK_UN);
    fclose($fp);
    return $result;
}
开发者ID:orangeal2o3,项目名称:pukiwiki-plugin,代码行数:19,代码来源:trackback.php

示例10: _plugin_code_write_cache

/**
 *  キャッシュに書き込む
 * 引数は添付ファイル名, HTML変換後のファイル
 */
function _plugin_code_write_cache($fname, $html)
{
    global $vars;
    // 添付ファイルのあるページ: defaultは現在のページ名
    $page = isset($vars['page']) ? $vars['page'] : '';
    // ファイル名にページ名(ページ参照パス)が合成されているか
    //   (Page_name/maybe-separated-with/slashes/ATTACHED_FILENAME)
    if (preg_match('#^(.+)/([^/]+)$#', $fname, $matches)) {
        if ($matches[1] == '.' || $matches[1] == '..') {
            $matches[1] .= '/';
        }
        // Restore relative paths
        $fname = $matches[2];
        $page = get_fullname(strip_bracket($matches[1]), $page);
        // strip is a compat
        $file = encode($page) . '_' . encode($fname);
    } else {
        // Simple single argument
        $file = encode($page) . '_' . encode($fname);
    }
    $fp = fopen(CACHE_DIR . 'code/' . $file . '.html', 'w') or die_message('Cannot write cache file ' . CACHE_DIR . 'code/' . $file . '.html' . '<br />Maybe permission is not writable or filename is too long');
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    rewind($fp);
    fputs($fp, $html);
    flock($fp, LOCK_UN);
    fclose($fp);
}
开发者ID:aterai,项目名称:pukiwiki-plus-i18n,代码行数:32,代码来源:code.inc.php

示例11: updateLastDatabaseError

function updateLastDatabaseError()
{
    global $boarddir;
    // Find out this way if we can even write things on this filesystem.
    // In addition, store things first in the backup file
    $last_settings_change = @filemtime($boarddir . '/Settings.php');
    // Make sure the backup file is there...
    $file = $boarddir . '/Settings_bak.php';
    if ((!file_exists($file) || filesize($file) == 0) && !copy($boarddir . '/Settings.php', $file)) {
        return false;
    }
    // ...and writable!
    if (!is_writable($file)) {
        chmod($file, 0755);
        if (!is_writable($file)) {
            chmod($file, 0775);
            if (!is_writable($file)) {
                chmod($file, 0777);
                if (!is_writable($file)) {
                    return false;
                }
            }
        }
    }
    // Put the new timestamp.
    $data = file_get_contents($file);
    $data = preg_replace('~\\$db_last_error = \\d+;~', '$db_last_error = ' . time() . ';', $data);
    // Open the backup file for writing
    if ($fp = @fopen($file, 'w')) {
        // Reset the file buffer.
        set_file_buffer($fp, 0);
        // Update the file.
        $t = flock($fp, LOCK_EX);
        $bytes = fwrite($fp, $data);
        flock($fp, LOCK_UN);
        fclose($fp);
        // Was it a success?
        // ...only relevant if we're still dealing with the same good ole' settings file.
        clearstatcache();
        if ($bytes == strlen($data) && filemtime($boarddir . '/Settings.php') === $last_settings_change) {
            // This is our new Settings file...
            // At least this one is an atomic operation
            @copy($file, $boarddir . '/Settings.php');
            return true;
        } else {
            // Oops. Someone might have been faster
            // or we have no more disk space left, troubles, troubles...
            // Copy the file back and run for your life!
            @copy($boarddir . '/Settings.php', $file);
        }
    }
    return false;
}
开发者ID:valek0972,项目名称:hackits,代码行数:53,代码来源:Subs-Admin.php

示例12: lockr

 static function lockr($fp)
 {
     set_file_buffer($fp, 0);
     if (!flock($fp, LOCK_SH)) {
         HakoError::lockFail();
     }
     rewind($fp);
 }
开发者ID:hiro0218,项目名称:hakoniwa,代码行数:8,代码来源:hako-ally.php

示例13: putstatus

 function putstatus()
 {
     $this->status['count'] = join(',', $this->status['count']);
     $fp = fopen($this->logname, 'wb') or die_message('cannot write ' . $this->logname);
     set_file_buffer($fp, 0);
     flock($fp, LOCK_EX);
     rewind($fp);
     foreach ($this->status as $key => $value) {
         fwrite($fp, $value . "\n");
     }
     flock($fp, LOCK_UN);
     fclose($fp);
 }
开发者ID:geoemon2k,项目名称:source_wiki,代码行数:13,代码来源:attach.inc.php

示例14: init

function init()
{
    $err = "";
    $chkfile = array(LOGFILE, TREEFILE);
    if (!is_writable(realpath("./"))) {
        error("カレントディレクトリに書けません<br>");
    }
    foreach ($chkfile as $value) {
        if (!file_exists(realpath($value))) {
            $fp = fopen($value, "w");
            set_file_buffer($fp, 0);
            if ($value == LOGFILE) {
                fputs($fp, "1,2002/01/01(月) 00:00,名無し,,無題,本文なし,,,,,,,,\n");
            }
            if ($value == TREEFILE) {
                fputs($fp, "1\n");
            }
            fclose($fp);
            if (file_exists(realpath($value))) {
                @chmod($value, 0666);
            }
        }
        if (!is_writable(realpath($value))) {
            $err .= $value . "を書けません<br>";
        }
        if (!is_readable(realpath($value))) {
            $err .= $value . "を読めません<br>";
        }
    }
    @mkdir(IMG_DIR, 0777);
    @chmod(IMG_DIR, 0777);
    if (!is_dir(realpath(IMG_DIR))) {
        $err .= IMG_DIR . "がありません<br>";
    }
    if (!is_writable(realpath(IMG_DIR))) {
        $err .= IMG_DIR . "を書けません<br>";
    }
    if (!is_readable(realpath(IMG_DIR))) {
        $err .= IMG_DIR . "を読めません<br>";
    }
    if (USE_THUMB) {
        @mkdir(THUMB_DIR, 0777);
        @chmod(THUMB_DIR, 0777);
        if (!is_dir(realpath(IMG_DIR))) {
            $err .= THUMB_DIR . "がありません<br>";
        }
        if (!is_writable(realpath(THUMB_DIR))) {
            $err .= THUMB_DIR . "を書けません<br>";
        }
        if (!is_readable(realpath(THUMB_DIR))) {
            $err .= THUMB_DIR . "を読めません<br>";
        }
    }
    if ($err) {
        error($err);
    }
}
开发者ID:Phalacrocorax,项目名称:futaba,代码行数:57,代码来源:futaba.php

示例15: ref_save

function ref_save($page)
{
    global $referer;
    if (PKWK_READONLY || !$referer || empty($_SERVER['HTTP_REFERER'])) {
        return true;
    }
    $url = $_SERVER['HTTP_REFERER'];
    // Validate URI (Ignore own)
    $parse_url = parse_url($url);
    if (empty($parse_url['host']) || $parse_url['host'] == $_SERVER['HTTP_HOST']) {
        return true;
    }
    if (!is_dir(TRACKBACK_DIR)) {
        die('No such directory: TRACKBACK_DIR');
    }
    if (!is_writable(TRACKBACK_DIR)) {
        die('Permission denied to write: TRACKBACK_DIR');
    }
    // Update referer data
    if (ereg("[,\"\n\r]", $url)) {
        $url = '"' . str_replace('"', '""', $url) . '"';
    }
    $filename = tb_get_filename($page, '.ref');
    $data = tb_get($filename, 3);
    $d_url = rawurldecode($url);
    if (!isset($data[$d_url])) {
        $data[$d_url] = array('', UTIME, 0, $url, 1);
    }
    $data[$d_url][0] = UTIME;
    $data[$d_url][2]++;
    $fp = fopen($filename, 'w');
    if ($fp === false) {
        return false;
    }
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    rewind($fp);
    foreach ($data as $line) {
        fwrite($fp, join(',', $line) . "\n");
    }
    flock($fp, LOCK_UN);
    fclose($fp);
    return true;
}
开发者ID:nsmr0604,项目名称:pukiwiki,代码行数:44,代码来源:trackback.php


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