当前位置:网站首页>统计php程序运行时间及设置PHP最长运行时间
统计php程序运行时间及设置PHP最长运行时间
2022-07-05 16:59:00 【游戏编程】
<?php $pagestartime=microtime(); ?> <?php 程序段?> <?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 "页面运行时间: $timecost 秒"; ?> 通常来说,默认的PHP程序最大运行时间是30s,如果你的程序运行超过这个时间限制,那么会有类似Maximum execution time of 30 seconds exceeded的报错。
有几种解决办法:
首先先检查是不是你的在做一些傻事,从而消耗了大量的CPU资源及时间,如果确实需要程序长时间运行才能得出结果,那么可以
1> 在php.ini中增加运行时间:
max_execution_time=300
1.
2> 在PHP文件中添加如下代码
ini_set(‘max_execution_time’, 300); //300 seconds = 5 minutes
1.
3> 使用.htaccess文件来增加运行时间:
其他一些常见配置参考:
如果你的环境是wordpress,那么请在config.php中,添加:
define(‘WP_MEMORY_LIMIT’, ‘128M’);
1.
如果你使用了其他一些框架,可以修改
ini_set(‘memory_limit’, ‘128M’);
默认情况下, php.ini 中配置的最大执行时间是 30 秒,这是由 php.ini 中的 max_execution_time 变量指定的。如果我们有一个需要花费很多时间的工作,比如要发送大量邮件,或者要进行庞大的数据统计分析工作。即使任务没有执行完毕,服务器也会在 30 秒后强行中止正在执行的程序。
1,修改最长执行时间的两种方法
(1)直接修改 php.ini 中 max_execution_time 的数值。

(2)如果没权限修改 php.ini 文件,或者我们想对某些页面进行单独设置。那么也可以在 PHP 程序页面中进行设置,代码如下(数值 0 表示没有执行时间的限制)。
1
ini_set ( ‘max_execution_time’ , ‘0’ );
2,如果使用IIS服务器,记得还要修改“活动超时”时间
如果是在 IIS 服务下运行 PHP 程序,会发现根据前面的方法修改后,执行长时间的操作还是会报错。错误信息如下:
HTTP 错误 500.0 - Internal Server Error
C:\websoft\php\php-cgi.exe - FastCGI 进程超过了配置的请求超时时

解决办法: IIS -> FastCGI 设置-> 双击"php-cgi.exe" ->“活动超时” ,根据需求将这个值提高。

作者:格格巫 MMQ!!
游戏编程,一个游戏开发收藏夹~
如果图片长时间未显示,请使用Chrome内核浏览器。
边栏推荐
- Tips for extracting JSON fields from MySQL
- [Jianzhi offer] 61 Shunzi in playing cards
- CMake教程Step4(安装和测试)
- 【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
- Machine learning compilation lesson 2: tensor program abstraction
- Embedded-c Language-2
- The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
- Kafaka technology lesson 1
- The second day of learning C language for Asian people
- In depth understanding of redis memory obsolescence strategy
猜你喜欢

WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响

Check the WiFi password connected to your computer

ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声

IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
深入理解Redis内存淘汰策略

Rider 设置选中单词侧边高亮,去除警告建议高亮

WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands

33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)

激动人心!2022开放原子全球开源峰会报名火热开启!
![[first lecture on robot coordinate system]](/img/3c/af056f0fe68b3244a3dc491ceb291d.png)
[first lecture on robot coordinate system]
随机推荐
Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
Redis+caffeine two-level cache enables smooth access speed
Embedded -arm (bare board development) -2
张平安:加快云上数字创新,共建产业智慧生态
7. Scala class
哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?
蚂蚁金服的暴富还未开始,Zoom的神话却仍在继续!
張平安:加快雲上數字創新,共建產業智慧生態
mysql5.6解析JSON字符串方式(支持复杂的嵌套格式)
Use of ThinkPHP template
Debug kernel code through proc interface
ICML 2022 | Meta propose une méthode robuste d'optimisation bayésienne Multi - objectifs pour faire face efficacement au bruit d'entrée
通过proc接口调试内核代码
Wsl2.0 installation
基于Redis实现延时队列的优化方案小结
[Jianzhi offer] 62 The last remaining number in the circle
腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
机器学习01:绪论
深入理解Redis内存淘汰策略
华为云云原生容器综合竞争力,中国第一!