当前位置:网站首页>統計php程序運行時間及設置PHP最長運行時間
統計php程序運行時間及設置PHP最長運行時間
2022-07-05 17:29: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內核瀏覽器。
边栏推荐
- IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
- winedt常用快捷键 修改快捷键latex编译按钮
- Use of ThinkPHP template
- Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
- C language to get program running time
- In depth understanding of redis memory obsolescence strategy
- Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
- 激动人心!2022开放原子全球开源峰会报名火热开启!
- thinkphp3.2.3
- WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands
猜你喜欢
Machine learning compilation lesson 2: tensor program abstraction
7. Scala class
MySQL之知识点(七)
机器学习02:模型评估
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
winedt常用快捷键 修改快捷键latex编译按钮
CMake教程Step1(基本起点)
Embedded UC (UNIX System Advanced Programming) -1
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计
随机推荐
What else do you not know about new map()
漫画:如何实现大整数相乘?(上) 修订版
Cartoon: how to multiply large integers? (integrated version)
MySql 查询符合条件的最新数据行
Embedded-c language-6
Embedded-c Language-3
忽米沄析:工业互联网标识解析与企业信息系统的融合应用
MYSQL group by 有哪些注意事项
7. Scala class
7.Scala类
Cartoon: interesting [pirate] question
排错-关于clion not found visual studio 的问题
Read the basic grammar of C language in one article
ternary operator
Embedded-c Language-1
Rider 设置选中单词侧边高亮,去除警告建议高亮
About JSON parsing function JSON in MySQL_ EXTRACT
漫画:一道数学题引发的血案
C # realizes crystal report binding data and printing 3-qr code barcode
Using C language to realize palindrome number