<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                **stream_wrapper_register** ( string **$protocol** , string **$classname** [, int **$flags** = 0 ] ) : bool 允許用戶實現自定義的協議處理器和流,用于所有其它的文件系統函數中(例如 fopen(),fread() 等) 成功時返回 **`TRUE`**, 或者在失敗時返回 **`FALSE`**(當`protocol`已經有處理者時,將返回 **`FALSE`** ) **參數** * protocol:待注冊的封裝的協議名字。 * classname:實現待注冊的協議的類名。 * flags:如果協議是URL協議,則應設置為STREAM_IS_URL。 默認值為0,表示本地流。 別名:stream_register_wrapper ~~~ <?php //自定義的包裝器類,此外php還提供了一個streamWrapper類 class VariableStream { var $position; var $varname; function stream_open($path, $mode, $options, &$opened_path) { $url = parse_url($path); $this->varname = $url["host"]; $this->position = 0; return true; } function stream_read($count) { $ret = substr($GLOBALS[$this->varname], $this->position, $count); $this->position += strlen($ret); return $ret; } function stream_write($data) { $left = substr($GLOBALS[$this->varname], 0, $this->position); $right = substr($GLOBALS[$this->varname], $this->position + strlen($data)); $GLOBALS[$this->varname] = $left . $data . $right; $this->position += strlen($data); return strlen($data); } function stream_tell() { return $this->position; } function stream_eof() { return $this->position >= strlen($GLOBALS[$this->varname]); } function stream_seek($offset, $whence) { switch ($whence) { case SEEK_SET: if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) { $this->position = $offset; return true; } else { return false; } break; case SEEK_CUR: if ($offset >= 0) { $this->position += $offset; return true; } else { return false; } break; case SEEK_END: if (strlen($GLOBALS[$this->varname]) + $offset >= 0) { $this->position = strlen($GLOBALS[$this->varname]) + $offset; return true; } else { return false; } break; default: return false; } } function stream_metadata($path, $option, $var) { if($option == STREAM_META_TOUCH) { $url = parse_url($path); $varname = $url["host"]; if(!isset($GLOBALS[$varname])) { $GLOBALS[$varname] = ''; } return true; } return false; } } stream_wrapper_register("var", "VariableStream") or die("Failed to register protocol"); $myvar = ""; $fp = fopen("var://myvar", "r+"); fwrite($fp, "line1\n"); fwrite($fp, "line2\n"); fwrite($fp, "line3\n"); rewind($fp); while (!feof($fp)) { echo fgets($fp); } fclose($fp); var_dump($myvar); ~~~ 與數據庫一起使用的流示例 ~~~ //sql數據 : CREATE TABLE IF NOT EXISTS `data` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `data` varchar(255) NOT NULL, `when_inserted` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; //現在使用流實現 class DBStream { private $_pdo; private $_ps; private $_rowId = 0; //實現用fopen等函數打開時執行的代碼 fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] ) : resource function stream_open($path, $mode, $options, &$opath) { //解析url并提取解析后數組里的path鍵的值 $url = parse_url($path); $url['path'] = substr($url['path'], 1); try{ //new PDO("mysql:host=localhost;dbname=dbname", $user, $pass) $this->_pdo = new PDO("mysql:host={$url['host']};dbname={$url['path']}", $url['user'], isset($url['pass'])? $url['pass'] : '', array()); } catch(PDOException $e){ return false; } switch ($mode){ case 'w' : $this->_ps = $this->_pdo->prepare('INSERT INTO data VALUES(null, ?, NOW())'); break; case 'r' : $this->_ps = $this->_pdo->prepare('SELECT id, data FROM data WHERE id > ? LIMIT 1'); break; default : return false; } return true; } //實現用fread等函數操作數據時執行的代碼 function stream_read() { $this->_ps->execute(array($this->_rowId)); if($this->_ps->rowCount() == 0) return false; $this->_ps->bindcolumn(1, $this->_rowId); $this->_ps->bindcolumn(2, $ret); $this->_ps->fetch(); return $ret; } //實現用fwrite,fputs等函數操作數據時執行的代碼 function stream_write($data) { $this->_ps->execute(array($data)); return strlen($data); } //檢索流的當前位置 function stream_tell() { return $this->_rowId; } //測試文件指針是否到了文件結束的位置使用feof等函數操作數據時執行的代碼 function stream_eof() { $this->_ps->execute(array($this->_rowId)); return (bool) $this->_ps->rowCount(); } //查找流中的特定位置使用fseek等函數操作數據時執行的代碼 function stream_seek($offset, $step) { //No need to be implemented } } stream_register_wrapper('db', 'DBStream'); $fr = fopen('db://testuser@localhost/testdb', 'r'); $fw = fopen('db://testuser:testpassword@localhost/testdb', 'w'); //可以接受上述兩種形式:對于前者,將使用默認密碼“” $alg = hash_algos();//返回已注冊的哈希算法列表 $al = $alg[array_rand($alg)];//隨機取出數組中的一個加密算法 $data = hash($al, rand(rand(0, 9), rand(10, 999))); // 要寫入的一些隨機數據 fwrite($fw, $data); // 將數據寫入包裝器 while($a = fread($fr, 256)){ //從包裝器循環的讀取數據 echo $a . '<br />'; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看