I have a script which I am attempting to execute in the command line using the command on my web server:
php /path_to_file/file.php 'alert' >> /path_to_log_directory/exec.log &
With obviously the two paths pointing at the location of the log and php file. The php file has the following code:
<?php
set_time_limit(3600);
require_once(dirname(dirname(__FILE__)).'/apps/init.php');
include (dirname(dirname(__FILE__)) . '/apps/avl_counter.php');
AvlCounter::$showReports = false;
AvlCounter::updateWholeInventory(false);
?>
Now the updateWholeInventory call a function "mysql_subquery" from the init.php file which is not in a class, the function it's calling is a global function. However, when I attempt the command line PHP command above, the terminal give me:
PHP Fatal error: Call to undefined function mysql_subquery() in /path_to_file/avl_counter.php on line 521
The file works fine on my local environment which is MAMP running apache but the webserver is running nginx and an older version of PHP. Can anyone help work out why this file executes fine on my local setup but not on my web server?
Here's a cut down version of init.php:
<?
date_default_timezone_set('America/Chicago');
require(dirname(__FILE__) . '/config.php');
if (DEBUG) {
ini_set('display_errors', true);
error_reporting(E_ALL ^ E_NOTICE);
} else {
error_reporting(0);
}
ob_start();
...
function mysql_subquery( $file=false,$line=false,$query=false) {
global $queryLog;
if (empty($queryLog))
$queryLog = array();
$start = microtime(true);
// ...
}
UPDATE
I am also getting the problem that when the PHP file executed in the shell, the init.php's code is being returned almost as text in the shell rather than being processed as a PHP script. Any ideas?
require_onceputprint_r(scandir(dirname(dirname(__FILE__))))to make sure it's pointing to the directory you think it is/apps/init.php?