LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2008, 12:58 PM   #1
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Rep: Reputation: 31
Debugging PHP?


I'm a newbie to PHP in general. I know some basic concepts but not a programer by any means. I have a script that used to run just fine under PHP4 .... I do # php quarantine_report.php and it generates and email reports for quarantined spam.

After an upgrade to PHP5 i excuate the same command and get nothing at all. I tried to turn on error reporting and debuging optoins in php.ini but no luck.

I there a way to debug php script while running?
Can someone point me in the right direction?
 
Old 12-03-2008, 01:04 PM   #2
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
Can you post your php.ini file as a start so we have something to look at? The only thing I can even think of at this time is to check your register_globals flag in the php.ini file. If you had it turned on, it will be off which is a default on all newer installations of php. That is the only start I can give you without seeing the file so I can understand better how it is used.
 
Old 12-03-2008, 07:27 PM   #3
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
I couldn't post php.ini due to character limitations.
register_globals was turned off and i turned it on, restarted httpd, retried .. but it didn't work. I also want add here that PHP in seems to be working otherwise. I have mailwatch website running like a champ. It seems that its only the script below that i'm having a trouble with.
The script itself is below:

Code:
#!/usr/bin/php -q
<?php
/*
 MailWatch for MailScanner
 Copyright (C) 2003  Steve Freegard (smf@f2s.com)

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

ini_set('error_log','syslog');
ini_set('html_errors','off');
ini_set('display_errors','on');
ini_set('implicit_flush','false');
require('/var/www/html/mailscanner/functions.php');

function quarantine_reconcile() {
 $quarantine = get_conf_var('QuarantineDir');
 $d = dir($quarantine) or die($php_errormsg);
 while(false !== ($f = $d->read())) {
  if (preg_match('/^\d{8}$/',$f)) {
   if(is_array(($array = quarantine_list_dir($f)))) {
    foreach($array as $id) {
     dbg("Updating: $id");
     $sql = "UPDATE maillog SET quarantined=1 WHERE id='$id'";
     dbquery($sql);
    }
   }
  }
 }
}

function quarantine_clean() {
 $oldest = date('U',strtotime('-'.QUARANTINE_DAYS_TO_KEEP." days"));
 $quarantine = get_conf_var('QuarantineDir');
 
 $d = dir($quarantine) or die($php_errormsg);
 while (false !== ($f = $d->read())) {
  // Only interested in quarantine directories (yyyymmdd)
  if (preg_match('/^\d{8}$/',$f)) {
   $unixtime = quarantine_date_to_unixtime($f);
   if ($unixtime < $oldest) { 
    // Needs to be deleted
    $array = quarantine_list_dir($f);
    dbg("Processing directory $f: found ".count($array)." records to delete");
    foreach($array as $id) {
     // Update the quarantine flag
     $sql = "UPDATE maillog SET quarantined = NULL WHERE id='$id'";
     dbquery($sql);
    }
    dbg("Deleting: ".escapeshellarg($quarantine.'/'.$f));
    exec('rm -rf '.escapeshellarg($quarantine.'/'.$f),$output,$return);
    if($return > 0) {
     echo "Error: $output\n";
    }
   }
  }
 }
 $d->close();
} 

function quarantine_date_to_unixtime($dirname) {
 $y = substr($dirname, 0, 4);
 $m = substr($dirname, 4, 2);
 $d = substr($dirname, 6, 2);
 $unixtime = mktime(0,0,0,$m,$d,$y);
 return $unixtime;
}

function dbg($text) {
 if(DEBUG) {
  echo $text."\n";
 }
}

function quarantine_list_dir($dir) {
 $dir = get_conf_var('QuarantineDir')."/$dir";
 $spam = "$dir/spam";
 $nonspam = "$dir/nonspam";
 $mcp = "$dir/mcp"; 
 $array = array();

 if (is_dir($dir)) {
  // Main quarantine
  $d = dir($dir) or die($php_errormsg);
  while (false !== ($f = $d->read())) {
   if ($f != '.' && $f != '..' && $f != 'spam' && $f != 'nonspam' && $f != 'mcp') {
    //dbg("Found $dir/$f");
    $array[] = $f;
   }
  }
  $d->close();
 }

 if (is_dir($spam)) {
  // Spam folder
  $d = dir($spam) or die($php_errormsg);
  while (false !== ($f = $d->read())) {
   if ($f != '.' && $f != '..' && $f != 'spam' && $f != 'nonspam' && $f != 'mcp') {
    //dbg("Found $spam/$f");
    $array[] = $f;
   }
  }
  $d->close();
 }

 if (is_dir($nonspam)) {
  $d = dir($nonspam) or die($php_errormsg);
  while (false !== ($f = $d->read())) {
   if ($f != '.' && $f != '..' && $f != 'spam' && $f != 'nonspam' && $f != 'mcp') {
    //dbg("Found $nonspam/$f");
    $array[] = $f;
   }
  }
  $d->close();
 }

 if (is_dir($mcp)) {
  $d = dir($mcp) or die($php_errormsg);
  while (false !== ($f = $d->read())) {
   if ($f != '.' && $f != '..' && $f != 'spam' && $f != 'nonspam' && $f != 'mcp') {
    //dbg("Found $mcp/$f");
    $array[] = $f;
   }
  }
  $d->close();
 }

 return $array;
}

switch($_SERVER['argv'][1]) {
 case '--clean':
  quarantine_clean();
  break;
 case '--reconsile':
  // I really should learn to spell...
  quarantine_reconcile();
  break;
 case '--reconcile':
  quarantine_reconcile();
  break;
 default:
  die('Usage: '.$_SERVER['argv'][0].' [--clean] [--reconcile]'."\n");
  break;
}
 

?>
I posted the original script because someone might figure which function i'm having a problem with and whether i need to switch something back in php.ini

Last edited by waelaltaqi; 12-03-2008 at 07:43 PM.
 
Old 12-03-2008, 08:13 PM   #4
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
parse error

Just another note which might help:

Code:
[root@box bin]# php -r quarantine_report.php
PHP Parse error:  syntax error, unexpected $end in Command line code on line 1
t
I researched the error message above and it usually means an open statement ... but in line 1? what am i missing !!!
 
Old 12-03-2008, 10:12 PM   #5
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
try executing the script with out the -r. I was getting the same problem until I stopped using -r.
 
Old 12-03-2008, 10:14 PM   #6
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
i did .. no output at all ..
it supposed to scan for quarantine mail and send a report and it will tell you for each user .. .
 
Old 12-03-2008, 10:27 PM   #7
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
Try checking your syslog. It looks like the script outputs errors to there as a way of suppression. Could you also post the functions.php file.
 
Old 12-03-2008, 10:39 PM   #8
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
Thanks a lot for the help. Nothing in syslog ... i checked it don't know how many times. As i said, PHP error handling is and is not leaving a trace either .... I've been reading around and it seems that a lot of developers had to rewrite their scripts to make them run ... not completely but changed a lot. Due to character limit, i can't post functions.php ....any other options?
 
Old 12-03-2008, 11:10 PM   #9
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
I can't be of too much help because I need some of the information from the functions.php file. However it did make me place a --clean or --reconcile. Do you have to do the same?
 
Old 12-03-2008, 11:30 PM   #10
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
Well i'm not sure at this point. Do you know of a way to downgrade to PHP4 on CentOS? or to rephrase, is there a repository that holds PHP4 binaries ..? Otherwise i have to compile from source which could be a little risky ... ?
 
Old 12-03-2008, 11:54 PM   #11
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
Also if you know a debugging tool that i can use for this. The one i've seen are usaually for code that is displayed on a browser and not for ones like i'm working one.. Just not sure what my next step should be..
 
Old 12-04-2008, 12:57 AM   #12
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Rep: Reputation: 37
Quote:
Originally Posted by waelaltaqi View Post
Also if you know a debugging tool that i can use for this. The one i've seen are usaually for code that is displayed on a browser and not for ones like i'm working one.. Just not sure what my next step should be..
try this one http://www.meandeviation.com/tutoria...-syntax-check/
 
Old 12-04-2008, 03:31 AM   #13
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
php -l /usr/local/bin/quarantine_report.php
no syntac errors deteced in /usr/local/bin/quarantine_report.php

The link RMLinux sent does the same thing. No errors were found anyways.
 
Old 12-04-2008, 03:49 AM   #14
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
WORKS!!!!

i moved the script to /var/www/html and called the script from a browser and it works ....!!!! not sure whats the reason for that ... Under PHP4, all i had to do is to excute php /usr/local/bin/quarantine_reports.php but in PHP5 that seems to not work...

an explanation will be appreciated but not necessary :-)
 
Old 12-05-2008, 12:05 AM   #15
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Rep: Reputation: 37
Quote:
Originally Posted by waelaltaqi View Post
i moved the script to /var/www/html and called the script from a browser and it works ....!!!! not sure whats the reason for that ... Under PHP4, all i had to do is to excute php /usr/local/bin/quarantine_reports.php but in PHP5 that seems to not work...

an explanation will be appreciated but not necessary :-)
try to edit your apache httpd.conf and
look for DocumentRoot [dir]....and <Directory></Directory> is correct.

also the types of directory and all the files it contains use
#chcon -R -h -t httpd_sys_content_t [/path/to/directory]. If your files is on different location this should be owned by apache which is httpd.

you can see the files by typing #ls -aZ
hope it helps.

it is not good to put your website on default /var/www/html dangerous!!! a lot of hackers can get you data :-)

Last edited by RMLinux; 12-05-2008 at 12:07 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Debugging PHP using Eclipse and PDT LXer Syndicated Linux News 0 06-18-2008 09:36 AM
LXer: Debugging PHP with Firebug LXer Syndicated Linux News 0 02-19-2007 11:16 PM
FC5 - PHP - Enable debugging, Segfault jbnewyork Linux - Server 0 11-14-2006 09:16 PM
Difference between kernel - debugging and application debugging topworld Linux - Software 2 03-30-2006 12:50 AM
Debugging PHP With PHPEdit and DBG - Session Start Timeout Has Expired SForsgren Linux - Software 0 07-22-2003 10:31 PM


All times are GMT -5. The time now is 02:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration