首頁  >  文章  >  後端開發  >  淺談PHP源碼六:關於stream_get_wrappers函數

淺談PHP源碼六:關於stream_get_wrappers函數

不言
不言原創
2018-06-28 16:47:311664瀏覽

這篇文章主要介紹了關於淺談PHP原始碼六:關於stream_get_wrappers函數,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

##stream_get_wrappers

(PHP 5)

stream_get_wrappers — 傳回註冊的資料流清單

Description

array stream_get_wrappers ( void )

Returns an indexed array containing the name of all stream wrappers available on the running system.

在某次其他函數的實作過程中需要知道url_stream_wrappers_hash變數的來源,

從而發現此函數也是從url_stream_wrappers_hash變數直接讀取數據,
於是有了對於此函數和url_stream_wrappers_hash變數的追蹤過程。
首先在standard資料夾下的streamsfuncs.c檔案中包含了此擴充功能的實作
其路徑如下:

   ==>PHP_FUNCTION(stream_get_wrappers)        //    streamsfuncs.c 548行
   ==>#define php_stream_get_url_stream_wrappers_hash() _php_stream_get_url_stream_wrappers_hash(TSRMLS_C)    //    php_stream.h    552行
   ==>PHPAPI HashTable *_php_stream_get_url_stream_wrappers_hash(TSRMLS_D)        //    streams/streams.c    58行
   ==>static HashTable url_stream_wrappers_hash;    //    全局静态变量,

從此函數的程式碼中我們可以看出它是直接遍歷php_stream_get_url_stream_wrappers_hash( )函數的傳回值,產生字串陣列

php_stream_get_url_stream_wrappers_hash()函數

而函數直接呼叫全域變數中的數據,此變數初始化和註冊過程追蹤如下:

url_stream_wrappers_hash初始化位置:==>int php_init_stream_wrappers(int module_number TSRMLS_DC)    //    streams.c     1395行  初始化数据流引用位置:==> if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE)     //    main.c 1765行,初始化,注册数据流 
添加默认注册的流程如下:==> zend_startup_modules(TSRMLS_C);    //    main.c 1843行,添加注册数据流==>zend_hash_apply(&module_registry, (apply_func_t)zend_startup_module_ex TSRMLS_CC);    //    zend_API.c    1519行==>ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC)    //    zend_API.c 1424行    ==>if (module->module_startup_func) {    //    zend_API.c    1470行==>PHP_MINIT_FUNCTION(basic)    //    basic_functions.c     3973行==> php_register_url_stream_wrapper("php", &php_stream_php_wrapper TSRMLS_CC);
 php_register_url_stream_wrapper("file", &php_plain_files_wrapper TSRMLS_CC);
 php_register_url_stream_wrapper("data", &php_stream_rfc2397_wrapper TSRMLS_CC);#ifndef PHP_CURL_URL_WRAPPERS
 php_register_url_stream_wrapper("http", &php_stream_http_wrapper TSRMLS_CC);
 php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper TSRMLS_CC);#endif 
     //     basic_functions.c    4073行,添加过程==>php_register_url_stream_wrapper    //    main/streams/streams.c    1450行

此次追蹤的時間跨度為一周,也算是經歷幾多磨難。但是最後總算是弄清楚其來源。

以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網!

相關推薦:

淺談PHP原始碼五:關於array 陣列的建立

白談PHP原始碼四:關於count函數

淺談PHP原始碼三:關於strrchr, strstr, stristr函數
#

以上是淺談PHP源碼六:關於stream_get_wrappers函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn