tags:

views:

65

answers:

5

hey all,

im getting this error, and i don't know why.

Fatal error: Maximum execution time of 30 seconds exceeded in E:\web\autoopti\thanks.php on line 65

The code I have for the PHP script is:

<?php
    $key = 129;

    $email = $_REQUEST["payer_email"];
    $first = $_REQUEST["first_name"];
    $last = $_REQUEST["last_name"];
    $acode = $_REQUEST["hash"];

    $txt = $email . "|" . $email . "|" . $first . "|" . $last . "|" . $acode;
    $outtxt = '';

    for($i=0;$i<strlen($txt);)
    {
        for($j=o;$j<strlen($key);$j++,$i++)
        {
            $outtxt .= $txt{$i} ^ $key{$j};
        }
    }

    echo "thanks";
?>

And the line the error message refers to is:

$outtxt .= $txt{$i} ^ $key{$j};

So, I'm guessing it's just taking too long for this line of code to do its work. Can somebody please help me fix this?

Thank you

+5  A: 

You have an infinite loop. $j starts at o (which is converted to 'o', since there is no o constant), rather than 0, and:

$j = 'o';
$j++;

results in $j = 'p' (even though 'o' + 1 is 1...)

It continues with $j eventually going from 'z' to 'aa'. Any non-numeric string is < any number, so the inner loop is infinite.

I'm not really sure what the point of the script is. But it looks like you're trying to do some home-grown encryption or hashing, which is often a mistake. Look at mcrypt and hash instead.

EDIT: My initial answer was wrong about the cause of the infinite loop.

Matthew Flaschen
+1 You're right, it was "just" an infinite inner loop. I would also humbly submit that the OP would be better off using a pre-made solution for whatever he's attempting.
deceze
He *does* mention that it was a script off a website. Whether that's a good idea or not is questionable.
Noufal Ibrahim
A: 

There's not much to wonder about here. Your code is taking too long to run. You can increase the timeout limit in your PHP config files. I would however recommend that you use the command line PHP interpreter to see where your program is taking all these 30 seconds and then figure out how to optimise it.

Noufal Ibrahim
I am using Winhost to host my php, however they do not have any options/config/ or anything to let me do php stuff. So basically what i get is what i get with no modification!
lucifer
And yes, I am aware of the irony :)
lucifer
just set the time in your script, at the very top: set_time_limit(60); // or 0 for "off" (not recommended)
Hans
Done. Fatal Error. Apparently, 60seconds isn't long enough either. Howsa bout we just make it an even 10minutes? :P
lucifer
Nonsense. There's probably a problem if it's taking that long. That's what you need to fix. A web page taking 60 seconds to service a single request? Increasing the time limit is not a solution.Also, why the -1? I hate it when people don't say *why* they don't approve of the answer.
Noufal Ibrahim
A: 

Use set_time_limit(0) if you want to continue with your code which will ignore any timeout setting in php.ini.

Shubham
Better to find out why something is exceeding it's time limit.
Blair McMillan
A: 
<?php
$key = 129;

$email = $_REQUEST["payer_email"];
$first = $_REQUEST["first_name"];
$last = $_REQUEST["last_name"];
$acode = $_REQUEST["hash"];

$txt = $email . "|" . $email . "|" . $first . "|" . $last . "|" . $acode;
$outtxt = '';

for($i=0;$i<strlen($txt);)
{
    for($j=0;$j<strlen($key);$j++,$i++)
    {
        $outtxt .=  ( $txt{ $i } ^ $key{$j} ) ;
    }
}

echo "thanks";

?>

Please see if this is the error fixed or comment me

Extjs Commander
You should specify what you have changed as well as why.
Blair McMillan
+1  A: 
Ankur Mukherjee