系統級函數涵蓋 PHP 運行時環境查詢、配置讀寫、擴展管理、進程資源控制等核心能力。按功能分類整理,附常數與最佳實踐,適合架構設計與除錯時快速檢索。
| 函數 | 功能 |
|---|---|
assert(mixed $assertion) | 檢查斷言,失敗觸發錯誤/異常 |
assert_options(int $what [, mixed $value]) | 設定/獲取斷言行為(如啟用/停用、回調) |
| 函數 | 功能 |
|---|---|
extension_loaded(string $name) | 檢查擴展是否已載入 |
get_loaded_extensions() | 返回所有已載入擴展名稱陣列 |
get_extension_funcs(string $module) | 返回指定模組提供的所有函數名稱 |
dl(string $library) | 動態載入擴展(僅 CLI/特定 SAPI 支援) |
| 函數 | 功能 | 作用域 |
|---|---|---|
ini_get(string $varname) | 獲取配置值 | 當前請求 |
ini_set(string $varname, string $newvalue) | 設定配置值 | 當前請求 |
ini_get_all() | 獲取所有配置陣列 | 全域+本地 |
get_cfg_var(string $option) | 獲取 php.ini 原始值 | 啟動時 |
ini_restore(string $varname) | 還原配置為 php.ini 值 | 當前請求 |
ini_alter() | ini_set 別名 | 當前請求 |
| 函數 | 功能 |
|---|---|
getenv(string $varname) | 獲取環境變數 |
putenv(string $assignment) | 設定環境變數(如 putenv('TZ=Asia/Taipei')) |
| 函數 | 功能 |
|---|---|
getmypid() | 當前 PHP 進程 ID |
getmyuid() / getmygid() | 腳本擁有者 UID/GID |
getmyinode() | 腳本檔案 inode 號 |
get_current_user() | 腳本擁有者用戶名 |
getlastmod() | 腳本最後修改時間 |
getrusage([int $who]) | 系統資源使用統計 |
memory_get_usage() | 當前腳本記憶體佔用 |
memory_get_peak_usage() | 峰值記憶體佔用 |
| 函數 | 功能 |
|---|---|
set_time_limit(int $seconds) | 設定腳本最大執行秒數(0=無限制) |
max_execution_time | ini 設定,同 set_time_limit |
| 函數 | 功能 |
|---|---|
get_include_path() | 獲取 include_path |
set_include_path(string $path) | 設定 include_path |
restore_include_path() | 還原 include_path |
get_included_files() | 已包含檔案絕對路徑列表 |
get_required_files() | get_included_files 別名 |
| 函數 | 功能 |
|---|---|
phpinfo([int $what]) | 輸出完整配置頁面 |
phpversion() | PHP 版本字串 |
php_sapi_name() | SAPI 類型(cli, fpm-fcgi, apache2handler...) |
php_uname() | 作業系統資訊 |
php_ini_scanned_files() | 掃描目錄下 .ini 列表 |
phpcredits([int $flag]) | 輸出貢獻者名單 |
php_logo_guid() / zend_logo_guid() | Logo GUID(已棄用) |
zend_version() | Zend Engine 版本 |
get_magic_quotes_gpc() / get_magic_quotes_runtime()set_magic_quotes_runtime()| 函數 | 功能 |
|---|---|
version_compare(string $v1, string $v2 [, string $op]) | 版本號比較,支援 <, >, =, <= 等運算符 |
main() | 掛名主函數,無實際作用 |
dl()、putenv()、ini_set() 等函數在共享主機常被禁用,生產代碼勿強依賴phpinfo()、get_included_files()、get_loaded_extensions() 輸出ini_set 僅影響當前請求,永久生效需修改 php.ini 或 .user.inidate_default_timezone_set() 或 putenv('TZ=...'),避免 date() 警告