Web Hosting Talk







View Full Version : I need trouble shoot, php infinite loop problem


adulu
03-21-2010, 04:20 AM
My site down twice but i still can't figure out what wrong come from.
Summary:i am use shared hosting.

http://ip/~adulu/test.php (timeout)(it's ip, therefore there is not dns problem)
below is chrome message.
message from chrome
408 Request Time-out

This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.
but open txt that are working fine as well as zip,jpg,html.
http://ip/~adulu/test.txt (fine)

JUST ONLY open .php will be time out?
it's been 3~4 hours still unable to open .php(timeout)
also only happened to on my account.

hosting provider restore my account, my site back to online at onece.

the hosting provider mean,Many of your php scripts are being executed but does not complete in a proper manner. There is a limit of how many php processes that each account may create simultaneously. That is why your http://ip/~adulu/test.php times out, while waiting for your other php scripts to finish executing.

in my limited php knowleage, if php infinite loop, my browser will down fast, visitor's browser down but hosting still in infinite loop.?

anyone know how to trobleshoot or have infinite loop php code for example?

thank you.
----
is this possible? my site that many page include php scripts.

this is for generate hyperlinks automatically.
there are 949 lines
is problem come from?
<?php
$keyword1= preg_replace("/875/", "<a href='http://785858.com'>8785</a>", "$keyword", 1);
$keyword2= preg_replace("/123/", "<a href='http://128783.com'>123</a>", "$keyword1", 1);
....etc
$keyword949= preg_replace("/558/", "<a href='http://8785578.com'>8585</a>", "$keyword948", 1);

echo "$keyword949";
?>

ScottSwezey
03-21-2010, 04:34 AM
<?php
$keyword1= preg_replace("/875/", "<a href='http://785858.com'>8785</a>", "$keyword", 1);
$keyword2= preg_replace("/123/", "<a href='http://128783.com'>123</a>", "$keyword1", 1);
....etc
$keyword949= preg_replace("/558/", "<a href='http://8785578.com'>8585</a>", "$keyword948", 1);

echo "$keyword949";
?>

First, ask your provider to kill the process for any/all of your active PHP processes. Then, if the issue comes back you can bet it is related to the code above. It's madness. I have no idea what you are trying to accomplish with it, but that isn't the way to do it.

CArmstrong
03-21-2010, 04:34 AM
What exactly are you trying to accomplish with your code? Regular expressions, while very powerful, can also be very intensive to calculate.

I would go for an alternate solution here.

adulu
03-21-2010, 05:05 AM
It's madness of 949 preg_replace lines
because i'd like my articles that would generate hyperlinks
just like wiki's articles
http://en.wikipedia.org/wiki/Wiki

ScottSwezey
03-21-2010, 05:16 AM
I have no idea what you are trying to accomplish with it, but that isn't the way to do it.

I think my original comment still stands.

adulu
03-21-2010, 08:11 AM
I think my original comment still stands.
Sorry for my English.
if you mean 875/", "<a href='http://785858.com'>8785</a>, it's just example.

ask your provider to kill the process for any/all of your active PHP processes
I have saw it on hostgator.
they allow client to kill the process in the client end.
does provider can find which .php files are having too many process.?

tim2718281
03-21-2010, 07:35 PM
It's madness of 949 preg_replace lines
because i'd like my articles that would generate hyperlinks
just like wiki's articles
http://en.wikipedia.org/wiki/Wiki

Can you explain what you want the program to do?

Give an example of the input and the required output.

horizon
03-21-2010, 08:38 PM
Looks like this request is about indexing each assembled values and output them as URL with the results. I would recommend using ReWrite from htaccess rather than replacing values. With ReWrite, you can dynamically output each results (the same way we would output categories and products from a gallery or E-Commerce script for instance).

speckl
03-21-2010, 09:29 PM
You need to cut that code down to 10 lines and see if it runs correctly.
If it does then split that file apart and require each file separately, however, that's a lot of replacements to process.

tim2718281
03-22-2010, 03:37 AM
Looks like this request is about indexing each assembled values and output them as URL with the results.

I don't think so.

Take the first two lines:

$keyword1= preg_replace("/875/", "<a href='http://785858.com'>8785</a>", "$keyword", 1);
$keyword2= preg_replace("/123/", "<a href='http://128783.com'>123</a>", "$keyword1", 1);

Notice that the first line creates "$keyword1", which is then used as the subject in the second line.

So there is a series of 949 transformations to the origin string "$keyword", which itself is not set anywhere.

I can't guess what the OP is trying to achieve.

And I don't know why the OP mentions an "infinite loop", because there is no loop.

adulu
03-22-2010, 08:13 AM
I don't think so.

Take the first two lines:

$keyword1= preg_replace("/875/", "<a href='http://785858.com'>8785</a>", "$keyword", 1);
$keyword2= preg_replace("/123/", "<a href='http://128783.com'>123</a>", "$keyword1", 1);
Notice that the first line creates "$keyword1", which is then used as the subject in the second line.

So there is a series of 949 transformations to the origin string "$keyword", which itself is not set anywhere.

I can't guess what the OP is trying to achieve.

And I don't know why the OP mentions an "infinite loop", because there is no loop.
I mean is it possible 949 preg_replace php lines which near infinite loop.?
i mentions infinite loop, because i don't know what's infinite loop.
maybe i write a infinite loop in unconsciously.

my site down again:crap:

tim2718281
03-22-2010, 09:27 AM
I mean is it possible 949 preg_replace php lines which near infinite loop.?



No.

Why don't you explain what you are trying to do, with examples?

energizedit
03-22-2010, 10:22 AM
What is the original contents of $keyword? is it dynamically generated or is it a static string? Why don't you just hard code the links into the page? Is there some reason you are using php? Is it talking to a database? Is this in a content management system (ie Joomla, Wordpress etc.)? Any of these answers would be helpful to know too.

mattle
03-22-2010, 11:51 AM
I mean is it possible 949 preg_replace php lines which near infinite loop.?
i mentions infinite loop, because i don't know what's infinite loop.
maybe i write a infinite loop in unconsciously.

my site down again:crap:



$a = "a";
while (preg_match("/a/", $a))
$a = preg_replace("/a/", "a", $a);


That's an infinite loop :) To have one, you do require a loop.

Since you're not using regular expressions for anything here but simple string replacement, I'd take a look at str_replace:


$find = array("123", "456", "789", ...);
$replace = array("<a href='http:123.com'>123</a>", ...);
$keyword = str_replace($find, $replace, $keyword);


No need to use regular expressions here or create 950 separate variables.

adulu
03-23-2010, 08:23 AM
$a = "a";
while (preg_match("/a/", $a))
$a = preg_replace("/a/", "a", $a); i did run it on my computer.
CPU up to 100%.

but my provider didn't mention that CPU unusually.
Many of your php scripts are being executed but does not complete in a proper manner. There is a limit of how many php processes that each account may create simultaneously. That is why your http://ip/~adulu/test.php (http://ip/%7Eadulu/test.php) times out, while waiting for your other php scripts to finish executing.
(http://ip/~adulu/test.php (http://ip/%7Eadulu/test.php) is empty,but still can't open it)


my site timeout 3 times, almost 48 hours once.

http://db.xn--8stv2u.tw/p/autolinks.txt my source code.
is there has loop?

No need to use regular expressions here or create 950 separate variables.
But how to generate hyperlinks if no create 950 separate variables?

thank you

adulu
03-23-2010, 08:37 AM
What is the original contents of $keyword? is it dynamically generated or is it a static string? Why don't you just hard code the links into the page? Is there some reason you are using php? Is it talking to a database? Is this in a content management system (ie Joomla, Wordpress etc.)? Any of these answers would be helpful to know too.
http://db.xn--8stv2u.tw/p/autolinks.txt (http://db.%E6%A1%8C%E5%B8%83.tw/p/autolinks.txt) original contents of $keyword
it's static string.

static string and database?
is there different?
static string is easy too.

mattle
03-23-2010, 09:39 AM
i did run it on my computer.
CPU up to 100%.


What the hell'd you do that for? I told you it was an infinite loop!


But how to generate hyperlinks if no create 950 separate variables?


Try this simple example if you don't believe me:


$originalText = "I'm glad that Google is refusing to censor search results in China.";
$search = array("Google", "China");
$replace = array(
"<a href='http://www.google.com/'>Google</a>",
"<a href='http://en.wikipedia.org/wiki/China'>China</a>");

$newText = str_replace($search, $replace, $originalText);
echo $newText;
Alternatively, if you don't understand how str_replace() works, go read the manual page for it. If you don't understand that, post your specific questions back here.

tim2718281
03-23-2010, 01:15 PM
http://db.xn--8stv2u.tw/p/autolinks.txt (http://db.%E6%A1%8C%E5%B8%83.tw/p/autolinks.txt) original contents of $keyword
it's static string.

static string and database?
is there different?
static string is easy too.

That link does not work.

I will try one final time:

Please explain what you are trying to do.

Don't post links, don't post code. Give an example of the input data you have, and show what you want the program to change it to.

adulu
03-24-2010, 12:24 AM
http://db.xn--8stv2u.tw/p/autolinks.txt link fixed.

sorry, i didn't say clean.
i am not asking for change programming.

i am asking, could you check my programming that whether has loop.
or whether it's too many lines cause loading heavy or PHP crash.(.php can't open, but .txt can open).

thanks.

tim2718281
03-24-2010, 06:57 AM
http://db.xn--8stv2u.tw/p/autolinks.txt link fixed.

sorry, i didn't say clean.
i am not asking for change programming.

i am asking, could you check my programming that whether has loop.
or whether it's too many lines cause loading heavy or PHP crash.(.php can't open, but .txt can open).

thanks.

Have you tested the program? I got:

PHP Notice: Undefined variable: zntit in /media/sdb9/timhome/workspace/sandpit/junk.php on line 996
PHP Notice: Undefined variable: zntit in /media/sdb9/timhome/workspace/sandpit/junk.php on line 997
PHP Notice: Undefined variable: imglinksa in /media/sdb9/timhome/workspace/sandpit/junk.php on line 1006
PHP Notice: Undefined variable: erth in /media/sdb9/timhome/workspace/sandpit/junk.php on line 1006
PHP Notice: Undefined variable: zntit in /media/sdb9/timhome/workspace/sandpit/junk.php on line 1006

mattle
03-24-2010, 08:27 AM
http://db.xn--8stv2u.tw/p/autolinks.txt link fixed.

sorry, i didn't say clean.
i am not asking for change programming.

i am asking, could you check my programming that whether has loop.
or whether it's too many lines cause loading heavy or PHP crash.(.php can't open, but .txt can open).

thanks.

I'm out...good luck Tim.