0

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?

11
  • Please enable full error reporting and run it again. Commented Aug 2, 2013 at 11:36
  • Above the require_once put print_r(scandir(dirname(dirname(__FILE__)))) to make sure it's pointing to the directory you think it is Commented Aug 2, 2013 at 11:38
  • can you show contents of /apps/init.php? Commented Aug 2, 2013 at 11:38
  • @ÁlvaroG.Vicario already have and still only shows the error that the mysql_subquery function cannot be found. Commented Aug 2, 2013 at 11:48
  • @SmokeyPHP done and using file_exists returns true so it's pointing at the right file Commented Aug 2, 2013 at 11:48

3 Answers 3

1

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.

This sounds like you don't have short tags enabled.

When running through CLI, PHP can be using different php.ini than it does under Apache. Run php -i to determine the config file(s) it is using, then edit the appropriate config file to enable short tags.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much. Had no idea they had two different PHP.ini files. The Shell PHP.ini didn't have short_tags open where as the apache version did :)
Yet another reason to use full <?php tags -.-
@SmokeyPHP It's actually not my application, and it's too big to manually go through and edit the <? to <?php
@Caleuanhopkins - How can this be the accepted answer? You claimed that replacing <? with <?php didn't fix the issue.
@ÁlvaroG.Vicario Because DCoder pointed out that shell/command line usesa different PHP.ini to apache, which I wasn't not aware of and is the basis for choosing the accepted answer. As far as I was aware you were referring to the apache PHP.ini which did have short_tags option turned on. In addition, changing <? to <?php broke the script in another location, thus causing another issue with the script. DCoder's answer fix the problem and didn't cause another issue to appear.
0

use this

 mysql_query()

instead of

 mysql_subquery()
  • you should use PDO or mysqli instead of mysql. mysql is already deprecated

4 Comments

The mysql_subquery is a function name in the init.php file that I'm trying to call, it's not the mysql_query() method. Yes I am aware of PDO, but this isn't my application and changing to PDO is not an option at this point.
i have no mysql_subquery in my php.ini why dont you post that line and also when you call it in php ?
why would you have that function in your PHP.ini? it's a custom function with the name mysql_subquery(). Please make sure you have read the question correctly.
init.php != php.ini
0

You've configured PHP to hide notices or all error messages, depending on a constant called DEBUG. Please compare:

<?php

error_reporting(E_ALL ^ E_NOTICE);
$foo1++;


error_reporting(0);
$foo2++;


error_reporting(E_ALL);
$foo3++;

Fiddle

Fix this and you'll get a clue about what's going on.

Edit

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?

Most likely, you haven't enabled short_open_tag. Of course, this fully explains the fatal error: if the code where you define function mysql_subquery() doesn't run, there's no way to use it :)

Weird thing is that you should have seen the source code pouring down your terminal. I guess that output buffering was masking it.

6 Comments

even remove that condition so the file reads: <? date_default_timezone_set('America/Chicago'); require(dirname(__FILE__) . '/config.php'); ob_start(); Doesn't change the issue
short_open_tag has been enabled in the PHP.ini
Removing inline error reporting settings does not mean that you've enabled it. It means that you're using the global values of the interpreter. Please try to understand the point of what I'm saying: you want PHP to notify you about the error, rather that blindly guess.
Are you sure? Replace <? with <?php and try again.
As I've stated in the question, I already have it returning an error: PHP Fatal error: Call to undefined function mysql_subquery() in /path_to_file/avl_counter.php on line 521 When I place: error_reporting(E_ALL ^ E_NOTICE); error_reporting(0); error_reporting(E_ALL); At the top of the file the error is the same
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.