1
wishcraft
Memory Bloating - PHP Script Executed from Cron Job

Hi how are you? I have been executing PHP and XOOPS from a Cron Job, I am finding up until version 2.5.3 this was happening fine however now there is a couple of warning and notices as well as protector consuming all memory on the system.

The following is the error I am recieving continually from the Cron Job, and I have tried to increase the allocated memory but this still causes and error with protector and is consumed.

PHP Notice:  Undefined indexSCRIPT_NAME in /home/chronola/public_html/class/xoopskernel.php on line 150
X
-Powered-ByPHP/5.3.8
Content
-typetext/html

<br />
<
b>Noticeb>:  Undefined indexSCRIPT_NAME in <b>/home/chronola/public_html/class/xoopskernel.phpbon line <b>150b><br /> PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 7680 bytesin /home/chronola/xoops_lib/modules/protector/include/precheck.inc.php on line 6 <br /> <b>Fatal errorb>:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 7680 bytesin <b>/home/chronola/xoops_lib/modules/protector/include/precheck.inc.phpbon line <b>6b><br />


The cronjob i am executing is:

/usr/bin/php /home/yoursite/public_html/modules/twitterbomb/cron/tweet.php


The following changes to protector so it only runs when an HTTP or HTTPS session occurs seem to fix the issue:

/xoops_lib/modules/protector/include/precheck.inc.php (local execution on cron fix)

require_once dirname(__FILE__).'/postcheck_functions.php' ;

if( ! 
defined'PROTECTOR_PRECHECK_INCLUDED' ) ) {
    require 
dirname(__FILE__).'/precheck.inc.php' ;
    return ;
}

define'PROTECTOR_POSTCHECK_INCLUDED' ) ;

if (!isset(
$_SERVER['SCRIPT_NAME'])) {
    return 
false;
}

if( ! 
class_exists'Database' ) ) return ;
protector_postcommon() ;

?>


/xoops_lib/modules/protector/include/postcheck.inc.php (local execution on cron fix)

require_once dirname(__FILE__).'/precheck_functions.php' ;

if( 
class_exists'Database' ) ) {
    require 
dirname(__FILE__).'/postcheck.inc.php' ;
    return ;
}

define'PROTECTOR_PRECHECK_INCLUDED' ) ;
define'PROTECTOR_VERSION' file_get_contentsdirname(__FILE__).'/version.txt' ) ) ;

if (!isset(
$_SERVER['SCRIPT_NAME'])) {
    return 
false;
}

// set $_SERVER['REQUEST_URI'] for IIS
if ( empty( $_SERVER'REQUEST_URI' ] ) ) {         // Not defined by IIS
    // Under some configs, IIS makes SCRIPT_NAME point to php.exe :-(
    
if ( !( $_SERVER'REQUEST_URI' ] = @$_SERVER['PHP_SELF'] ) ) {
        
$_SERVER'REQUEST_URI' ] = $_SERVER['SCRIPT_NAME'];
    }
    if ( isset( 
$_SERVER'QUERY_STRING' ] ) ) {
        
$_SERVER'REQUEST_URI' ] .= '?' $_SERVER'QUERY_STRING' ];
    }
}

protector_prepare() ;

?>


/class/xoopskernel.php - Replace this function
function pathTranslation()
    {
        
/**
         * *#@+
         * Host abstraction layer
         */
        
if (!isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['SCRIPT_FILENAME'])) {
            
$_SERVER['PATH_TRANSLATED'] =& $_SERVER['SCRIPT_FILENAME']; // For Apache CGI
        
} else if (isset($_SERVER['PATH_TRANSLATED']) && !isset($_SERVER['SCRIPT_FILENAME'])) {
            
$_SERVER['SCRIPT_FILENAME'] =& $_SERVER['PATH_TRANSLATED']; // For IIS/2K now I think :-(
        
}
        
/**
         * User Mulitbytes
         */
        
if (empty($_SERVER['REQUEST_URI']) && isset($_SERVER['SCRIPT_NAME'])) { // Not defined by IIS
            // Under some configs, IIS makes SCRIPT_NAME point to php.exe :-(
            
if (!($_SERVER['REQUEST_URI'] = @$_SERVER['PHP_SELF'])) {
                
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
            }
            if (isset( 
$_SERVER['QUERY_STRING'])) {
                
$_SERVER['REQUEST_URI'] .= '?' $_SERVER['QUERY_STRING'];
            }
        }
    }
Resized Image
http://www.ohloh.net/accounts/226400

Follow, Like & Read:-

twitter.com/RegaltyFamily
github.com/Chronolabs-Cooperative
facebook.com/DrAntonyRoberts

Login

Who's Online

433 user(s) are online (308 user(s) are browsing Support Forums)


Members: 0


Guests: 433


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits