Page 1 of 1

Php crashing apache without error message.

Posted: Mon Sep 21, 2009 8:31 pm
by Nor
Hello, My first time posting here so if I do something wrong please let me know.

I've been running apache for a few months now.
here is my setup for my development box.
Windows Vista basic 64bit quad core
Apache/2.2.13 (Win32)
-PHP/5.3.0

I've haven't had any problems developing scripts for my websites but I've come
across a very serious error I can't resolve.

I have been searching forums and post and sites without finding anything useful
so after 3 days I've decided to post about it.

This code causes apache to crash on both my development box and my public webserver.
My development box is windows bases, the public server is linux based.
My Web host is tired of restarting apache every time I call and has offered NO help with
this issue.

here is the code, please let me know if you see anything wrong with it.
I might just be missing something.
This is just the start of a new script i'm working on. I entered this and then tested the script
to ensure I had not made any errors. Then apache crashed.

Code: Select all

<?php
    //Options for 404.php autoban script
    $banfile = 'Banlist.txt';
    $htaccess_file = '.htaccess';
    $attempts = 10;
 
    $fp = fopen($banfile, 'r');
 
    while (!feof($fp)) {
      $line = trim(fgets($fp));
      $pieces = explode("\t", $line);
      $client = trim($pieces[0]);
      $count = trim($pieces[1]);
      $error_count[$client] = $count;
    }
    fclose($fp);
?>

Re: Php crashing apache without error message.

Posted: Mon Sep 21, 2009 8:37 pm
by Eran
what is the size of the Banlist.txt file?

Re: Php crashing apache without error message.

Posted: Tue Sep 22, 2009 5:11 am
by Nor
the banlist file contains this
'127.0.0.1[tab]10
'
[tab] is the actual tab character "\t" and there is a newline at the end.

Re: Php crashing apache without error message.

Posted: Tue Sep 22, 2009 6:34 am
by dude81
I dont see anything wrong with the code on my system. It could be a problem with 5.3 or could be a problem with .htaccess. What do the apache error logs say?

Re: Php crashing apache without error message.

Posted: Tue Sep 22, 2009 5:39 pm
by Nor
As my subject header notes
Php crashing apache without error message.
I've 3 log files to view
httpd_access_log which does not show the URL request
httpd_error_log which shows no errors other than apache restarting and overwritten the PID file
php_error.txt which is created but nothing is written to it.

may I ask, what version of apache and php are you running?
-edit-
here is my htaccess file

Code: Select all

Options -Indexes
ErrorDocument 404 /404.php

Re: Php crashing apache without error message.

Posted: Tue Sep 22, 2009 7:11 pm
by Nor
ok, i've updated php to the latest snapshot for windows
Now I'm getting an error message

NOTICE: Undefined offset: 1 in a:\www\404.php on line 13

It's like explode is not doing its job. What did I get myself into.

Everything is default ini file with php, and only necessary customization of http.conf

Re: Php crashing apache without error message.

Posted: Tue Sep 22, 2009 7:15 pm
by John Cartwright
Try replacing explode() with preg_split() to handle the more unusual whitespace circumstances.

Code: Select all

$pieces = preg_split("/\s+/", $line);
Secondly, you might want to add a var_dump($peices); right after your explode/preg_split to see if the tokenizing was successful.

Re: Php crashing apache without error message.

Posted: Tue Sep 22, 2009 7:46 pm
by Nor
Thank you for the lighting fast reply.

first I added var_dump and it returned
(ps, never used this function before.
My collage professor is a $List_of_words_not_allowed_here)

Code: Select all

 
array(2) {
  [0]=>
  string(9) "127.0.0.1"
  [1]=>
  string(1) "4"
}
array(1) {
  [0]=>
  string(0) ""
}
 
Please correct me if i'm wrong but
array(2) says there are 2 elements in said array.
array(1) says there are 1 elements in said array

so i'm reading my newline into the variable
Remove the newline from banlist.txt the magic of php is working again.

Re: Php crashing apache without error message.

Posted: Tue Sep 22, 2009 8:21 pm
by dude81
You can't get rid of new line, if the number of clients being banned are more than one.
So always parse array(2) in the loop which is getting the required fields values

Code: Select all

 
array(2)[0] = will get you the IP
array(2)[1]= will get the number of attempts made by the client