php-fpm log location
php-fpm settings
; php80 php_flag[display_errors] = off php_admin_flag[log_errors] = on php_admin_value[error_log] = /var/opt/remi/php80/log/php-fpm/www-error.log
ls -ld /var/opt/remi/php80/log/php-fpm/www-error.log
drwxrwx--- 2 apache root 23 Jul 7 16:49 /var/opt/remi/php80/log/php-fpm
memory
# Returns the amount of memory allocated to PHP
memory_get_usage()
<?php echo memory_get_usage() . "\n"; // 36640 $a = str_repeat("Hello", 4242); echo memory_get_usage() . "\n"; // 57960 unset($a); echo memory_get_usage() . "\n"; // 36744 ?>
# Runtime set memory limit
* 只在 mod_php 時才有效, FPM 情況無效
ini_set('memory_limit', '16M');
php-fpm Settings
/etc/php5/fpm/php.ini
memory_limit = 256M
/etc/php5/fpm/php-fpm.conf
php_value[memory_limit] = 256M
... PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 268435464 bytes) in /home/vhosts/datahunter.org/public_html/tim.php on line 21
... PHP Fatal error: Maximum execution time of 30 seconds exceeded in /home/vhosts/datahunter.org/public_html/tim.php on line 19
execution time
$start_time = microtime(true); $end_time = microtime(true); $execution_time = ($end_time - $start_time); echo " Execution time: " . $execution_time . " seconds";
# us (1s=10^6)
microtime() 当前 Unix 时间戳以及微秒数
Test script
<? error_reporting(E_ALL & ~E_NOTICE); echo "max_execution_time: " . ini_get('max_execution_time') . PHP_EOL; echo "memory_limit: " . ini_get('memory_limit') . PHP_EOL; echo memory_get_usage() . PHP_EOL; echo "========" . PHP_EOL; // counting $start_time = microtime(true); $big_array = array(); for ($i = 0; $i < 1000000; $i++) { for ($j = 0; $j < 1000000; $j++) { hash('sha256', 'run time consume function'); $big_array[] = $i; } } $end_time = microtime(true); $execution_time = ($end_time - $start_time); echo "Execution time: " . $execution_time . " us" . PHP_EOL; echo "Usage: " . memory_get_usage() . PHP_EOL; ?>