標籤:
一. streams是幹嘛的: 用於統一檔案、網路、資料壓縮等類檔案操作方式,並為這些類檔案操作提供一組通用的函數介面。 二. stream是具有流式行為的資來源物件,這個對象有一個封裝類 例如: print_r(stream_get_wrappers());//返回所有可用流封裝器的名稱/*Array( [0] => php /** 它是PHP用來處理IO流的封裝類,如php://stdin php://stdout **/ [1] => file [2] => glob [3] => data [4] => http [5] => ftp [6] => zip [7] => compress.zlib [8] => https [9] => ftps [10] => phar)*/ 三. PHP的預設封裝類就是file:// ;; 所以readfile(‘/path/to/somefile.txt‘)或者readfile(‘file:///path/to/somefile.txt‘),這兩種方式是等效的 四. 註冊自己的封裝器(自訂 協議處理器和流),用於所有其它的檔案系統函數中(例如 fopen() , fread() 等) 五. PHP還可以通過context和filter對封裝類進行修飾和增強。 1. 關於context,如PHP通過stream_context_create()來設定擷取檔案逾時時間 $opts = array( ‘http‘=>array( ‘method‘=>"GET", ‘timeout‘=>60) );$context = stream_context_create($opts);$html =file_get_contents(‘http://www.jb51.net‘, false, $context); 2. 關於filter過濾器,首先來看看PHP有哪些內建的過濾器: print_r(stream_get_filters());/*Array( [0] => convert.iconv.* [1] => mcrypt.* [2] => mdecrypt.* [3] => string.rot13 [4] => string.toupper [5] => string.tolower [6] => string.strip_tags [7] => convert.* [8] => consumed [9] => dechunk [10] => zlib.*)*/ 3. 自訂的過濾器 通過stream_filter_register()和內建的php_user_filter可建立自訂的過濾器
php-streams擴充