getrusage
(PHP 4, PHP 5)
getrusage — Gets the current resource usages
Description
array getrusage
([ int
$who
= 0
] )This is an interface to getrusage(2). It gets data returned from the system call.
Parameters
-
who
-
If
who
is 1, getrusage will be called withRUSAGE_CHILDREN
.
Return Values
Returns an associative array containing the data returned from the system call. All entries are accessible by using their documented field names.
Examples
Example #1 getrusage() example
<?php
$dat = getrusage();
echo $dat["ru_nswap"]; // number of swaps
echo $dat["ru_majflt"]; // number of page faults
echo $dat["ru_utime.tv_sec"]; // user time used (seconds)
echo $dat["ru_utime.tv_usec"]; // user time used (microseconds)
?>
Notes
Note: This function is not implemented on Windows platforms.
See Also
- Your system's man page on getrusage(2)
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Изменение поведения PHP
- PHP Опции и Информация
- assert_options
- assert
- cli_get_process_title
- cli_set_process_title
- dl
- extension_loaded
- gc_collect_cycles
- gc_disable
- gc_enable
- gc_enabled
- gc_mem_caches
- get_cfg_var
- get_current_user
- get_defined_constants
- get_extension_funcs
- get_include_path
- get_included_files
- get_loaded_extensions
- get_magic_quotes_gpc
- get_magic_quotes_runtime
- get_required_files
- get_resources
- getenv
- getlastmod
- getmygid
- getmyinode
- getmypid
- getmyuid
- getopt
- getrusage
- ini_alter
- ini_get_all
- ini_get
- ini_restore
- ini_set
- magic_quotes_runtime
- main
- memory_get_peak_usage
- memory_get_usage
- php_ini_loaded_file
- php_ini_scanned_files
- php_logo_guid
- php_sapi_name
- php_uname
- phpcredits
- phpinfo
- phpversion
- putenv
- restore_include_path
- set_include_path
- set_magic_quotes_runtime
- set_time_limit
- sys_get_temp_dir
- version_compare
- zend_logo_guid
- zend_thread_id
- zend_version
Коментарии
getrusage() reports kernel counters that are updated only once application loses context and a switch to kernel space happens. For example on modern Linux server kernels that would mean that getrusage() calls would return information rounded at 10ms, desktop kernels - at 1ms.
getrusage() isn't usable for micro-measurements at all - and getmicrotime(true) might be much more valuable resource.
Note that this function returns rusage of the current process. In a web environment where you have long running apache processes that serve several requests with PHP executions, this will return cumulative timings and is therefore not suitable for telling how much user time your used. The best you could do is to call getrusage() once at the beginning and once at the end and calculate the difference.
BeOS support is removed in PHP 7.3:
https://github.com/php/php-src/blob/php-7.3.0alpha1/NEWS