Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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?
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?
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 ... ?
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..
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..
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 :-)
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 :-)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.