当前位置:网站首页>Count the running time of PHP program and set the maximum running time of PHP
Count the running time of PHP program and set the maximum running time of PHP
2022-07-05 17:29:00 【Game programming】
<?php $pagestartime=microtime(); ?> <?php Procedures section ?> <?php $pageendtime = microtime(); echo $pageendtime."
"; $starttime = explode(" ",$pagestartime); $endtime = explode(" ",$pageendtime); $totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1]; $timecost = sprintf("%s",$totaltime); echo " Page runtime : $timecost second "; ?> Generally speaking , default PHP The maximum running time of the program is 30s, If your program runs beyond this time limit , Then there will be something similar Maximum execution time of 30 seconds exceeded The error of .
There are several solutions :
First, check whether you are doing something stupid , It consumes a lot of CPU Resources and time , If you really need the program to run for a long time to get results , Then you can.
1> stay php.ini Increase the running time :
max_execution_time=300
1.
2> stay PHP Add the following code to the file
ini_set(‘max_execution_time’, 300); //300 seconds = 5 minutes
1.
3> Use .htaccess File to increase running time :
Other common configuration references :
If your environment is wordpress, Then please config.php in , add to :
define(‘WP_MEMORY_LIMIT’, ‘128M’);
1.
If you use other frameworks , You can modify
ini_set(‘memory_limit’, ‘128M’);
By default , php.ini The maximum execution time configured in is 30 second , This is from php.ini Medium max_execution_time Variable . If we have a job that takes a lot of time , For example, send a lot of emails , Or a huge statistical analysis of data . Even if the task is not completed , The server will 30 Seconds later, forcibly abort the executing program .
1, Two ways to modify the maximum execution time
(1) Directly modifying php.ini in max_execution_time The numerical .
(2) If you don't have permission to modify php.ini file , Or we want to set some pages separately . Then you can also PHP Set in the program page , The code is as follows ( The number 0 Indicates that there is no restriction on execution time ).
1
ini_set ( ‘max_execution_time’ , ‘0’ );
2, If you use IIS The server , Remember to revise “ Activity timed out ” Time
If it's in IIS Run under service PHP Program , You will find that after modification according to the previous method , An error will still be reported after a long operation . The error message is as follows :
HTTP error 500.0 - Internal Server Error
C:\websoft\php\php-cgi.exe - FastCGI The process exceeded the configured request timeout
terms of settlement : IIS -> FastCGI Set up -> double-click "php-cgi.exe" ->“ Activity timed out ” , Increase this value as needed .
author : Gegwu MMQ!!
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- Embedded -arm (bare board development) -2
- 33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)
- CMake教程Step6(添加自定义命令和生成文件)
- 張平安:加快雲上數字創新,共建產業智慧生態
- 漫画:有趣的海盗问题 (完整版)
- 漫画:寻找无序数组的第k大元素(修订版)
- CMake教程Step5(添加系统自检)
- 菜刀,蚁剑,冰蝎,哥斯拉的流量特征
- Design of electronic clock based on 51 single chip microcomputer
- Cartoon: a bloody case caused by a math problem
猜你喜欢
基于Redis实现延时队列的优化方案小结
mysql中取出json字段的小技巧
MYSQL group by 有哪些注意事项
Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition
Complete solution instance of Oracle shrink table space
c#图文混合,以二进制方式写入数据库
Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
Use of ThinkPHP template
统计php程序运行时间及设置PHP最长运行时间
Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
随机推荐
The first lesson of EasyX learning
Embedded UC (UNIX System Advanced Programming) -1
C language to get program running time
Flask solves the problem of CORS err
哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?
Embedded -arm (bare board development) -2
统计php程序运行时间及设置PHP最长运行时间
thinkphp3.2.3
Judge whether a number is a prime number (prime number)
机器学习01:绪论
Read the history of it development in one breath
Debug kernel code through proc interface
漫画:如何实现大整数相乘?(上) 修订版
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
漫画:有趣的【海盗】问题
CMake教程Step3(添加库的使用要求)
ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
Cloud security daily 220705: the red hat PHP interpreter has found a vulnerability of executing arbitrary code, which needs to be upgraded as soon as possible
[Web attack and Defense] WAF detection technology map
Cartoon: a bloody case caused by a math problem