当前位置:网站首页>統計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內核瀏覽器。
边栏推荐
- Is it safe and reliable to open futures accounts on koufu.com? How to distinguish whether the platform is safe?
- ThoughtWorks global CTO: build the architecture according to needs, and excessive engineering will only "waste people and money"
- 腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
- Little knowledge about C language (array and string)
- 机器学习02:模型评估
- 排错-关于clion not found visual studio 的问题
- Cmake tutorial step6 (add custom commands and generate files)
- 一文了解Go语言中的函数与方法的用法
- Is it safe for China Galaxy Securities to open an account? How long can I buy stocks after opening an account
- Embedded UC (UNIX System Advanced Programming) -3
猜你喜欢
Complete solution instance of Oracle shrink table space

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

CVPR 2022 best student paper: single image estimation object pose estimation in 3D space

Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition

CMake教程Step1(基本起点)

一个满分的项目文档是如何书写的|得物技术

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

How to write a full score project document | acquisition technology

High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body

Check the WiFi password connected to your computer
随机推荐
漫画:如何实现大整数相乘?(整合版)
Mysql5.6 parsing JSON strings (supporting complex nested formats)
2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
Check the WiFi password connected to your computer
C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
thinkphp3.2.3
Matery主题自定义(一)黑夜模式
33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)
MySQL之知识点(七)
About JSON parsing function JSON in MySQL_ EXTRACT
Oracle缩表空间的完整解决实例
漫画:有趣的【海盗】问题
張平安:加快雲上數字創新,共建產業智慧生態
Force deduction solution summary 729- my schedule I
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Database design in multi tenant mode
2022年信息系统管理工程师考试大纲
漫画:一道数学题引发的血案
Machine learning 02: model evaluation