Jump to content

PHP Times Out if Apache has been running for a while?


Kryptix

Recommended Posts

I have a really annoying problem, PHP just sits there until it times out if Apache has been running for a while. If you restart Apache it works absolutely fine! It's only when using the two functions before to encode/decode a username. I'm using the latest XAMPP on Windows Server 2003 although it also happens on my Windows XP box.

 

function encode_username($username) {
$username = strtolower($username);
$clean = '';
for($i = 0;$i < strlen($username);$i++) {
	$c = ord($username{$i});
	if($c >= 97 && $c <= 122) {
		$clean .= chr($c);
	}
	else if($c >= 48 && $c <= 57) {
		$clean .= chr($c);
	}
	else {
		$clean .= ' ';
	}
}
$clean = trim($clean);
if(strlen($clean) > 12) {
	$clean = substr($clean, 0, 12);
}
$hash = '0';
for($i = 0;$i < strlen($clean);$i++) {
	$c = ord($clean{$i});
	$hash = bcmul($hash, 37);
	if($c >= 97 && $c <= 122) {
		$hash = bcadd($hash, (1 + $c) - 97);
	}
	else if($c >= 48 && $c <= 57) {
		$hash = bcadd($hash, (27 + $c) - 48);
	}
}
return $hash;
}

 

function decode_username($hash) {
if(!$hash) {
	return 'invalid_name';
}
$username = '';
while($hash) {
	$i = bcmod($hash, 37);
	$hash = bcdiv($hash, 37);
	if($i == '0') {
		$username = ' '.$username;
	}
	else if($i < 27) {
		if(bcmod($hash, 37) == '0') {
			$username = chr(($i + 65) - 1).$username;
		}
		else {
			$username = chr(($i + 97) - 1).$username;
		}
	}
	else {
		$username = chr(($i + 48) - 27).$username;
	}
}
return $username;
}

 

Does anyone know what could be causing this? The exact code has been working fine on many other systems so it seems like a configuration problem. I really need to get this resolved but I'm baffled.

Link to comment
Share on other sites

Why don't you debug the problem and create a benchmark to see how fast the functions are en/decoding? If it hangs obviously there's something wrong with the logic in it, I don't see anything on hand that would make it time out. How many usernames is it encoding?

Link to comment
Share on other sites

Why don't you debug the problem and create a benchmark to see how fast the functions are en/decoding? If it hangs obviously there's something wrong with the logic in it, I don't see anything on hand that would make it time out. How many usernames is it encoding?

Just one. I've made it loop through 100,000 usernames and it encodes them all flawlessly, but if Apache has been running for a while (it varies) it randomly hangs. Sometimes it takes 3 days, other times it takes a few minutes. As I said, they work on other systems so I'm pretty sure it's a configuration problem but I don't have any idea where to start looking. I don't get how they can run perfectly 100,000 times in a row and then suddenly start timing out for no apparent reason.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.