PHP:超过最大执行时间30秒 [英] PHP: Maximum execution time of 30 seconds exceeded

查看:348
本文介绍了PHP:超过最大执行时间30秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php应用程序调用一个名为Client的类。每次我得到一种时间错误。我认为它是SQL,但它转向它的指向类本身。


致命错误:在C:\Program文件(x86)中超过30秒的最大执行时间\Apache Software Foundation \Apache2 .2\htdocs\ClientPortal\classes\Connections.php on line 3




 <?php 
session_start();
class Connections {// line 3

有没有人知道这里发生了什么? p>

感谢,



比利

解决方案

PHP脚本有一个允许执行的最大时间,如在php.ini中所声明的。



希望通过添加以下行:

  ini_set('max_execution_time',123456) 

其中123456是您想要限制的秒数。



您还可以使用 set_time_limit 函数,其中I只是刚刚发现和假设做同样的事情。



您可以在php.ini文件中更改它,但是您可能正在使用您的脚本执行批处理操作或某事。你不会希望一个最终用户正在访问的PHP脚本坐在那里挂了30秒或更长时间,所以你最好把它保持默认或甚至在php.ini文件中,并根据需要设置max_execution_time。



如下面的注释中所指出的,你可以将max_execution_time设置为0来停止错误的发生,但是seegee是正确的说,至少对于一个Web请求,你真的不应该这样做。对于php命令行解释器,这种行为是默认的。



如果你看到这个问题,由最终用户通过Web请求使用,您可能需要做一些分析来解决真正的原因。如果您在执行MySQL查询,请先开启缓慢查询纪录 a>。当你忘记了一个索引,或者你在做其他一些低效的事情时,它是特别好的让你知道。



你也可以推几个 $ s = microtime(true);你的东西(); var_dump(microtime(true) - $ s); 周围的事情,得到一个模糊的概述哪些位是减慢的事情,只是确保你不要留下任何后来! >

如果您仍然无法找到根本原因,请在本地计算机上设置 xdebug 并运行分析器。扩展可以作为预编译的Windows二进制文件(虽然似乎有一个混乱的版本数组)。您可以使用 wincachegrind 检查运行分析器的结果。


I have a php app that calls a class called Client. Every so often I get a sort of time out error. I thought it was SQL at first but it turns its pointing to the class itself.

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\ClientPortal\classes\Connections.php on line 3

<?php
    session_start();
    class Connections { //line 3

Does anyone know what's going on here?

thanks,

Billy

解决方案

PHP scripts have a maximum time they're allowed to execute for, as declared in the php.ini.

You can circumvent this if you really want by adding the following line:

ini_set('max_execution_time', 123456);

where 123456 is the number of seconds you want the limit to be.

You can also use the set_time_limit function, which I only just found out about and assume does the same thing. I've always just done the former though.

You can change it in the php.ini file, but you might be using your script to do a batch operation or something. You wouldn't want a PHP script that is being accessed by an end user to sit there hanging for 30 seconds or more though, so you're better off leaving it at the default or even turning it down in the php.ini file, and setting the max_execution_time on an as-needed basis.

As seengee points out in the comment below, you can set the max_execution_time to 0 to stop the error from ever happening, but seengee is right to say that at least for a web request, you really shouldn't do this. For the php command line interpreter, this behaviour is the default though.

If you're seeing this problem for things that are supposed to be used by end-users through a web request, you might have to do some profiling to work out the real cause. If you're doing MySQL queries, start by turning on the slow query log. It's particularly good at letting you know when you've forgotten an index, or if you're doing something else inefficient.

You can also shove a few $s = microtime(true); yourstuff(); var_dump(microtime(true)-$s); things around to get a vague overview of which bits are slowing things down, just make sure you don't leave any of them in afterwards!

If you're still struggling to find the root cause, set xdebug up on your local machine and run the profiler. The extension is available as a precompiled windows binary (although there seems to be a confusing array of versions). You can inspect the results of running the profiler using wincachegrind.

这篇关于PHP:超过最大执行时间30秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆