PHP函数
影响 PHP 行为的扩展
## 一、APC — Alternative PHP Cache (可选 PHP 缓存) #### 1、APC 函数 - apc_add — 缓存一个变量到数据存储 bool apc_add (string $key, mixed $var [,int $ttl = 0 ] ) array apc_add (array $values [,mixed $unused = NULL [,int $ttl = 0 ]] ) - apc_cas — 用新值更新旧值 bool apc_cas ( string $key , int $old , int $new ) - apc_clear_cache — 清除APC缓存 bool apc_clear_cache ([ string $cache_type = "" ] ) - apc_delete — 从用户缓存中删除某个变量 mixed apc_delete ( string $key ) - apc_exists — 检查APC中是否存在某个或者某些key mixed apc_exists ( mixed $keys ) - apc_fetch — 从缓存中取出存储的变量 mixed apc_fetch ( mixed $key [, bool &$success ] ) - apc_inc — 递增一个储存的数字 int apc_inc ( string $key [, int $step = 1 [, bool &$success ]] ) #### 2、APCIterator — APCIterator 类 - APCIterator::_\_construct — 构造一个 APCIterator 迭代器对象 public APCIterator::_\_construct ( string $cache ) - APCIterator::current — 获取当前项 public mixed APCIterator::current ( void ) - APCIterator::getTotalCount — 获取总数 public int APCIterator::getTotalCount ( void ) - APCIterator::getTotalHits — 获取缓存命中数 public int APCIterator::getTotalHits ( void ) - APCIterator::getTotalSize — 获取所有缓存的尺寸大小 public int APCIterator::getTotalSize ( void ) - APCIterator::key — 获取迭代器的键 public string APCIterator::key ( void ) - APCIterator::next — 移到下一项 public void APCIterator::next ( void ) - APCIterator::rewind — 倒退迭代器 public void APCIterator::rewind ( void ) - APCIterator::valid — 检查当前位置是否有效 public void APCIterator::valid ( void ) ## 二、错误处理 — 错误处理和日志记录 - debug_backtrace — 产生一条回溯跟踪(backtrace) array debug_backtrace([int$options = DEBUG_BACKTRACE_PROVIDE_OBJECT[,int$limit = 0 ]] ) var_dump(debug_backtrace()); - debug_print_backtrace — 打印一条回溯。 void debug_print_backtrace([int $options= 0 [,int $limit = 0 ]] ) - error_clear_last — 清除最近一次错误 void error_clear_last(void) print_r(error_get_last()); - error_get_last — 获取最后发生的错误 array error_get_last(void) - error_log — 发送错误信息到某个地方 Bool error_log(string $message[,int$message_type= 0 [,string $destination[,string $extra_headers]]] ) Message :应该被记录的错误信息。 Destination:目标。它的含义描述于以上,由 message_type 参数所决定。 extra_headers :额外的头。当 message_type 设置为 1 的时候使用。 该信息类型使用了 mail() 的同一个内置函数。 message_type:设置错误应该发送到何处。可能的信息类型有以下几个: 0 默认,发送到 PHP 的系统日志 1 发送到参数 destination 设置的邮件地址。 参数 extra_headers 只有在这个类型里才会被用到。 2 不再是一个选项。 3 被发送到位置为 destination 的文件里。 字符 message 不会默认被当做新的一行。 4 直接发送到 SAPI 的日志处理程序中。 - error_reporting — 设置应该报告何种 PHP 错误 Int error_reporting ([int $level] ) ```php // 关闭所有PHP错误报告 error_reporting(0); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // 报告 E_NOTICE也挺好 (报告未初始化的变量 // 或者捕获变量名的错误拼写) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // 除了 E_NOTICE,报告其他所有错误 error_reporting(E_ALL ^ E_NOTICE); // 报告所有 PHP 错误 (参见 changelog) error_reporting(E_ALL); // 报告所有 PHP 错误 error_reporting(-1); // 和 error_reporting(E_ALL); 一样 ini_set('error_reporting', E_ALL); ``` - restore_error_handler — 在使用 set_error_handler() 改变错误处理函数之后,此函数可以 用于还原之前的错误处理程序(可以是内置的或者也可以是用户所定义的函数)。 bool restore_error_handler(void) - restore_exception_handler — 在使用 set_exception_handler() 改变异常处理函数之后,此函数可以 用于还原之前的异常处理程序(可以是内置的或者也可以是用户所定义的函数)。 bool restore_exception_handler (void) - set_error_handler — 设置用户自定义的错误处理函数 mixed set_error_handler ( callable $error_handler [, int $error_types = E_ALL | E_STRICT ] ) - set_exception_handler — 设置用户自定义的异常处理函数 callable set_exception_handler (callable $exception_handler ) - trigger_error — 产生一个用户级别的 error/warning/notice 信息 bool trigger_error ( string $error_msg [,int $error_type= E_USER_NOTICE ] ) - user_error — trigger_error 的别名 ## 三、OPcache - opcache_compile_file — 该函数可以用于在不用运行某个 PHP 脚本的情况下,编译该 PHP 脚本并将其添加到字节码缓存中去。 该函数可用于在 Web 服务器重启之后初始化缓存,以供后续请求调用。 boolean opcache_compile_file ( string $file ) - opcache_get_configuration — 获取缓存的配置信息 array opcache_get_configuration ( void ) - opcache_get_status — 获取缓存的状态信息 array opcache_get_status ([ boolean $get_scripts = TRUE ] ) - opcache_invalidate — 废除脚本缓存 boolean opcache_invalidate ( string $script [, boolean $force = FALSE ] ) - opcache_is_script_cached — Tells whether a script is cached in OPCache boolean opcache_is_script_cached ( string $file ) - opcache_reset — 重置字节码缓存的内容 boolean opcache_reset ( void ) ## 四、输出缓冲控制 - flush — 刷新输出缓冲 刷新PHP程序的缓冲,而不论PHP执行在何种情况下(CGI ,web服务器等等)。该函数将当前为止程序的所有输出发送到用户的浏览器。flush() 函数不会对服务器或客户端浏览器的缓存模式产生影响。因此,必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。个别web服务器程序,特别是Win32下的web服务器程序,在发送结果到浏览器之前,仍然会缓存脚本的输出,直到程序结束为止。有些Apache的模块,比如mod_gzip,可能自己进行输出缓存,这将导致flush()函数产生的结果不会立即被发送到客户端浏览器。 ```php if (ob_get_level() == 0) ob_start(); for ($i = 0; $i<10; $i++){ echo "<br> Line to show."; echo str_pad('',4096)."\n"; ob_flush(); flush(); sleep(2); } echo "Done."; ob_end_flush(); ``` - ob_clean — 清空(擦掉)输出缓冲区 - ob_end_clean — 清空(擦除)缓冲区并关闭输出缓冲 此函数丢弃最顶层输出缓冲区的内容并关闭这个缓冲区。如果想要进一步处理缓冲区的内容,必须在ob_end_clean()之前调用ob_get_contents(),因为当调用ob_end_clean()时缓冲区内容将被丢弃。 - ob_end_flush — 冲刷出(送出)输出缓冲区内容并关闭缓冲 这个函数将送出最顶层缓冲区的内容(如果里边有内容的话),并关闭缓冲区。如果想进一步处理缓冲区中的内容,必须在ob_end_flush()之前调用 ob_get_contents(),因为在调用ob_end_flush()后缓冲区内容被丢弃。 - ob_flush — 冲刷出(送出)输出缓冲区中的内容 这个函数将送出缓冲区的内容(如果里边有内容的话)。如果想进一步处理缓冲区中的内容,必须在ob_flush()之前调用ob_get_contents() ,因为在调用ob_flush()之后缓冲区内容将被丢弃。 - ob_get_clean — 得到当前缓冲区的内容并删除当前输出缓。 ob_get_clean() 实质上是一起执行了 ob_get_contents() 和 ob_end_clean()。 - string ob_get_contents ( void ) — 返回输出缓冲区的内容,但不清除它 - string ob_get_flush ( void ) — 刷出(送出)缓冲区内容,以字符串形式返回内容,并关闭输出缓冲区。 - int ob_get_length ( void ) — 返回输出缓冲区内容的长度 - int ob_get_level ( void ) — 返回输出缓冲机制的嵌套级别 - array ob_get_status ([ bool $full_status = FALSE ] ) — 得到所有输出缓冲区的状态 - string ob_gzhandler ( string $buffer , int $mode ) — 在ob_start中使用的用来压缩输出缓冲区中内容的回调函数。 - void ob_implicit_flush ([ int $flag = true ] ) — 打开/关闭绝对刷送 - array ob_list_handlers ( void ) — 列出所有使用中的输出处理程序。 - bool ob_start ([ callback $output_callback [, int $chunk_size [, bool $erase ]]] ) — 打开输出控制缓冲 - bool output_add_rewrite_var ( string $name , string $value ) — 添加URL重写器的值(Add URL rewriter values) - bool output_reset_rewrite_vars ( void ) — 重设URL重写器的值(Reset URL rewriter values) ## 五、PHP 选项和信息 - ini_alter — 别名 ini_set - ini_get_all — 获取所有配置选项 - ini_get — 获取一个配置选项的值 - ini_restore — 恢复配置选项的值 - ini_set — 为一个配置选项设置值 - int memory_get_peak_usage([bool $real_usage= false] ) — 返回分配给 PHP 内存的峰值 - int memory_get_usage([bool $real_usage= false] ) — 返回分配给 PHP 的内存量 - php_ini_loaded_file — 取得已加载的 php.ini 文件的路径 - php_ini_scanned_files — 返回从额外 ini 目录里解析的 .ini 文件列表 - php_logo_guid — 获取 logo 的 guid。自 PHP 5.5.0 起,已经废弃并移除此函数 - php_sapi_name — 返回 web 服务器和 PHP 之间的接口类型 - php_uname — 返回运行 PHP 的系统的有关信息 - phpcredits — 打印 PHP 贡献者名单 - phpinfo — 输出关于 PHP 配置的信息 - phpversion — 获取当前的PHP版本 - putenv — 设置环境变量的值 - set_include_path — 设置 include_path 配置选项 - set_magic_quotes_runtime — 设置当前 magic_quotes_runtime 配置选项的激活状态 - set_time_limit — 设置脚本最大执行时间 - int gc_mem_caches() — Reclaims memory used by the Zend Engine memory manager,没参数 - string get_cfg_var(string $option) — 获取 PHP 配置选项的值 - string get_current_user() — 获取当前 PHP 脚本所有者名称 - array get_defined_constants([bool $categorize= false] ) — 返回所有常量的关联数组,键是常量名,值是常量值 - array get_extension_funcs(string $module_name) — 返回模块函数名称的数组 - array get_loaded_extensions([bool $zend_extensions= false] ) — 返回所有编译并加载模块名的 array - bool get_magic_quotes_gpc(void) — 获取当前 magic_quotes_gpc 的配置选项设置 - bool get_magic_quotes_runtime(void) — 获取当前 magic_quotes_runtime 配置选项的激活状态 - array get_resources ([string $type] ) — Returns active resources - string getenv(string $varname) — 获取一个环境变量的值 - get_required_files — 别名 get_included_files - string get_include_path(void) — 获取当前的 include_path 配置选项 - array get_included_files(void) — 返回被 include 和 require 文件名的 array - restore_include_path — 还原 include_path 配置选项的值 - getlastmod — 获取页面最后修改的时间 - Getmygid — 获取当前 PHP 脚本拥有者的 GID - getmyinode — 获取当前脚本的索引节点(inode) - getmypid — 获取 PHP 进程的 ID - getmyuid — 获取 PHP 脚本所有者的 UID - getopt — 从命令行参数列表中获取选项 - getrusage — 获取当前资源使用状况 - magic_quotes_runtime — 别名 set_magic_quotes_runtime - sys_get_temp_dir — 返回用于临时文件的目录 - version_compare — 对比两个「PHP 规范化」的版本数字字符串 - zend_logo_guid — 获取 Zend guid - zend_thread_id — 返回当前线程的唯一识别符 - zend_version — 获取当前 Zend 引擎的版本 - assert_options — 设置/获取断言的各种标志 - assert — 检查一个断言是否为 FALSE - string cli_get_process_title(void) — Returns the current process title - bool cli_set_process_title(string $title) — Sets the process title - bool dl (string $library) — 运行时载入一个 PHP 扩展 - bool extension_loaded(string $name) — 检查一个扩展是否已经加载 - int gc_collect_cycles() — 强制收集所有现存的垃圾循环周期,没参数 - void gc_disable() — 停用循环引用收集器,没参数 - void gc_enable() — 激活循环引用收集器,没参数 - bool gc_enabled() — 返回循环引用计数器的状态,没参数 ## 六、Xhprof — 层次式性能分析器 XHProf 是一个轻量级的分层性能测量分析器。 在数据收集阶段,它跟踪调用次数与测量数据,展示程序动态调用的弧线图。 它在报告、后期处理阶段计算了独占的性能度量,例如运行经过的时间、CPU 计算时间和内存开销。 函数性能报告可以由调用者和被调用者终止。 在数据搜集阶段 XHProf 通过调用图的循环来检测递归函数,通过赋予唯一的深度名称来避免递归调用的循环。 XHProf 包含了一个基于 HTML 的简单用户界面(由 PHP 写成)。 基于浏览器的用户界面使得浏览、分享性能数据结果更加简单方便。 同时也支持查看调用图。 XHProf 的报告对理解代码执行结构常常很有帮助。 比如此分层报告可用于确定在哪个调用链里调用了某个函数。 XHProf 对两次运行进行比较(又名 "diff" 报告),或者多次运行数据的合计。 对比、合并报告,很像针对单次运行的“平式视图”性能报告,就像“分层式视图”的性能报告。 - xhprof_disable— 停止 xhprof 分析器,并返回此次运行的 xhprof 数据。 - xhprof_enable— 启动 xhprof 性能分析器 - xhprof_sample_disable— 停止 xhprof 性能采样分析器 - xhprof_sample_enable— 以采样模式启动 XHProf 性能分析 ```php Array( [ct] => 1 // number of calls. [wt] => 419 // wall/wait time (ms). [cpu] => 0 // cpu time. [mu] => 8264 // memory usage (bytes). [pmu] => 0 // peak memory usage. ) ```
顶部
收展
底部
[TOC]
目录
PHP函数 字符串函数
PHP函数 数组函数
PHP函数 文件目录函数
日期时间函数
MySQL函数
正则函数
数学函数
cURL 函数
XML函数
加密函数
Session函数
URL函数
Apache 函数
Bzip2 压缩与归档扩展
GNU Readline 针对命令行的扩展
网络函数
进程控制
变量与类型相关扩展函数
影响 PHP 行为的扩展
相关推荐
PHP基础
PHP设计模式
PHP算法
PHP版本