Apache (possible PHP) Problem
Posted: Fri Apr 07, 2006 11:47 am
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, thanks in advance for any help you can give me with this problem.
I have Apache 1.3.34 running on XP Proffessional with PHP 4.3.11. For about a year now its worked fine. I use it to test php code I write for a remote server. However, for the past week when I try to access a particular php script Apache gives this error message:
[i]
[error] Server ran out of threads to serve requests. Consider raising the ThreadsPerChild setting[/i]
and then Apache crashes.
I've done some searching and a lot of people mention that this a sign of a DoS attack. That couldn't be the problem on my server for 2 reasons, first that I'm the only one who accesses it, and 2 I've checked the log files.
Solutions that I've tried:
I upped the ThreadsPerChild to 1000, the server took longer to crash, and used more system resources.
Upgraded Apache: I uninstalled 1.3.33 (which I had previously) and ran the 1.2.34 installer. It used the same conf file. That did not fix the problem.
Here's the php file that crashes the server. It gets a list of files in a directory (text files) and puts them in an array. Then three functions are called by other pages to display these articles. Please excuse my messy code. If its too difficult to follow, I can try to comment it. Thank you again, in advance, for any help you can provide.Code: Select all
<?PHP
//IMPORTANT! This Variable must be set to the file name of the php script!
$phpfiledir = "NewsInclude.php";
$dir = 'C:/Web/icta/news/';
$counter = "0";
//Reads files from the news directory.
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != $phpfiledir && $file != "viewarticle.php" && $file != "header.php" && $file != "footer.php" && $file != "allarticles.php") {
//echo "$file<br>";
if($file != "addarticle") {
//echo "$file<br>";
$stories[$counter] = $file;
//"<br>";
}
$counter++;
}
}
closedir($handle);
//echo "<br>"; - Debugging
//print_r($stories); //- Debugging
//echo "<br><br><br><br><br>";
//Reads and Prints txt Stories
//print_r($stories);
$x = count($stories);
$x++;
$y = 1;
//echo "<br>"; //- Debugging
//echo "$x"; //- Debugging
while ($y < $x) {
//print_r($stories[$x]);
//echo $y;
//echo $storeis[$y];
//echo "<br>";
$news_file = file_get_contents('http://localhost/ICTA/News/' . $stories[$y]);
$news_file_array = explode("/endtitle/",$news_file);
$all_news[$y] = $news_file_array;
//print_r($all_news[$y]);
//echo "<br><br><br>";
$y++;
//echo $x;
}
//print_r($all_news);
//echo "<br><br><br>";
//Function Declaration for Template Pages
//To display news somewhere, insert the following script (without the slash and star):
/*
<?PHP
include("news\NewsInclude.php"); //This must be the directory and filename of the main script.
display_articles(1); // The number determines the number of articles displayed.
?>
*/
$all_news_version2 = $all_news;
//print_r($all_news_version2);
function display_articles($num_articles,$split_num,$directory) {
global $all_news_version2;
$all_news = $all_news_version2;
//print_r($all_news);
$numarttot=count($all_news);
$numarttot++;
$num = 0;
while ($num < $num_articles) {
$num_second = 0;
while ($num_second < count($all_news[$num])) {
if(strlen($all_news[$numarttot-$num][$num_second]) > 40) {
$all_news[$numarttot-$num][$num_second] = split(" ",$all_news[$numarttot-$num][$num_second],($split_num+1));
$new_count = 0;
while ($new_count < $split_num) {
//echo "Output";
//echo "<br>";
echo $all_news[$numarttot-$num][$num_second][$new_count];
echo " ";
$new_count ++;
}
echo " . . . ";
}
else {
echo "<strong>";
echo '<a href="',$directory,'viewarticle.php?article=', urlencode($all_news[$numarttot-$num][$num_second]), '">';
echo $all_news[$numarttot-$num][$num_second];
echo "</a>";
echo "</strong>";
}
echo "<br>";
$num_second++;
}
//echo "This is the number!: ";
$num ++;
}
//echo $directory;
//print_r($allnews[1]);
}
//echo "<br>";
//display_articles(3,20,'');
function readnews ($article_name) {
global $all_news;
$counter = 1;
$count_news = count($all_news);
$count_news ++;
while($counter < $count_news) {
if(eregi($article_name,$all_news[$counter][0])) {
echo $all_news[$counter][1];
}
$counter ++;
}
//print_r($all_news);
}
function display_articles_long($num_articles,$split_num,$directory) {
global $all_news_version2;
$all_news = $all_news_version2;
//print_r($all_news);
$num = 0;
while ($num < $num_articles) {
$num_second = (0);
while ($num_second < count($all_news[$num])) {
if(strlen($all_news[$num][$num_second]) > 40) {
$all_news[$num][$num_second] = split(" ",$all_news[$num][$num_second],($split_num+1));
$new_count = 0;
while ($new_count < $split_num) {
//echo "Output";
//echo "<br>";
echo $all_news[$num][$num_second][$new_count];
echo " ";
$new_count ++;
}
echo " . . . ";
}
else {
echo "<strong>";
echo '<a href="',$directory,'viewarticle.php?article=', urlencode($all_news[$num][$num_second]), '">';
echo $all_news[$num][$num_second];
echo "</a>";
echo "</strong>";
}
echo "<br>";
$num_second++;
}
//echo "This is the number!: ";
$num ++;
}
//echo $directory;
//print_r($allnews[1]);
}
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]