-
Fatal error Maximum execution time of 30 seconds exceeded
Hi,
I wonder why I get this error on my localhost machine.
Fatal error Maximum execution time of 30 seconds exceeded
php.ini is 30 secs by default but when I do my login page and login, it will load for very long and give this error, I wonder whats went wrong? Is it my next page php file too big.
Thanks in advanced :)
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
yes, that's the jist of it. either your next page is too big, or you probably have a continuous loop that keeps loading things when you shouldn't.
post your code. for the "next page."
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
A login page should never, ever take 30 seconds. You must have an infinite loop or similar programming error in there.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Thanks for the reply :) Actually my next page got around 1000 lines of coding, is it part of the problem as my next page is just convert from a html file to php and starting got around 100 lines of php codings for restriction base on session.
If thats the main course, can I have all the php coding then follow by a php coding or javascript that display a newly create html files for the content?
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
1000 lines is nothing. Except a good place for a bug to hide.
Other than that, I have no clue what you said.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Thanks for your reply :) if 1000 lines isn't the main problem, is there any program can spot error on my files and fix it if possible?
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
I haven't heard of a PHP linter, but perhaps there is one.
Other than that, there's only yourself. Write out messages during page processing and call flush() to make sure they're immediately sent to the client. This way, you can narrow down where it gets stuck.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Look at the line number. Fatal error. Dies on that line which caused the infinity. :)
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Thanks :) But I don't quite understand the flush thingy, I don't know where should I put. I think I will show my coding better.
PHP Code:
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "index.html";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php echo $logoutAction ?>
Then below all is all those lots HTML coding.
If people go to the above restrict page, my website will redirect as http://localhost/Web/login.php?acces...protected1.php
then after it redirect to login.php, when user login, it will load very slow and show the fatal error msg.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Quote:
Originally Posted by klutz
Look at the line number. Fatal error. Dies on that line which caused the infinity. :)
Thanks for your first post to me :) My line 5 is } as I have post my php codes above.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
well, you should be posting the source to the page that loads slow, (or at least -some- of that page, because I for one am not going to skim through 1000 lines of code), not the page before it.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Just use session_destroy() rather than manually unsetting all the variables (and setting them to null first, which is redundant).
I cannot understand why a login page would exceed 30 seconds execution. You must have a loop or some external call. Neither of which should be necessary.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Quote:
Originally Posted by kows
well, you should be posting the source to the page that loads slow, (or at least -some- of that page, because I for one am not going to skim through 1000 lines of code), not the page before it.
the above coding is the restricted page coding which load slow. Actually the scenrio is like this,
loginpage.php
restrictedpage.php
restrictedpage2.php
restrictedpage3.php
loginfail.php
When user use login.php and it will redirect to restrictedpage.php. But when user go either one the restrictedpage without login, the url will change to http://localhost/Web/login.php?acces...estricted2.php and a login.php will prompt to login, once user login, it will load very slow and get that error message.
Maybe I should post my login.php coding also?
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
That would be a most phantastic(sp?) idea.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
hmm.. how do I input that and flush tag in properly?
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
My login page codings.
PHP Code:
<?php require_once('Connections/connLogin.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "protected.php";
$MM_redirectLoginFailed = "loginfailure.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_connLogin, $connLogin);
$LoginRS__query=sprintf("SELECT username, user_password FROM phpbb_users WHERE username=%s AND user_password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $connLogin) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Nothing here that can really take that long. You've got some seriously weird issues.
Back to the flush trick. It basically works like this:
Code:
echo "Reached this point.<br>\n"; flush();
Put this in many places in your script, changing the echo text a bit each time. This way you can narrow down where it hangs.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
sorry to ask that is the coding only post @ starting of php coding to the end of php coding, no need to put in after ?> right?
But I try to put but they never give any errors or I put it the wrong way? I should open all php files that got link with login then put the code eg like below.
<?php require_once('Connections/connLogin.php'); ?>
echo "Reached this point.<br>\n"; flush();
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
echo "Reached this point.<br>\n"; flush();
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
echo "Reached this point.<br>\n"; flush();
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
echo "Reached this point.<br>\n"; flush();
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
echo "Reached this point.<br>\n"; flush();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
echo "Reached this point.<br>\n"; flush();
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "restricted.php";
$MM_redirectLoginFailed = "loginfailure.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_connLogin, $connLogin);
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Use code tags.
Those echos are good. Put one before the include, too.
No, you don't need ?> at the end of the file, though I personally consider it good style. Although I have to admit it has a problem, namely stray newlines after it.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
PHP Code:
<?php
echo 'Reached line '. __LINE__ . '<br>\n'; flush();
?>
:)
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
That's a nice trick. Never thought of it before.
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
Hi thanks for all the reply again. I think the problem should be lies on my restricted php page.
I do all those flush thingy, I get this error on that restricted page
Reached line 29
\n
Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\wwwroot\Login\login.php:29) in c:\Inetpub\wwwroot\Login\login.php on line 72
That line 72 is header("Location: ". $MM_restrictGoTo);
I research the information as I think the error is common. But I dunno how should I debug, some call me to put ob_flush also dunno how should I go about it?
-
Re: Fatal error Maximum execution time of 30 seconds exceeded
You should ignore it while debugging. It's telling you that it cannot send HTTP headers after it has sent body content, which is true. Once you remove the debug output, it will work again.
Question, though: if the redirect is prevented, does the page load completely? If so, then the error is indeed on the page you redirect to, not the login page.