No output using PHP CLI
I'm not used to the PHP CLI (always used PHP via http), so maybe it's something simple I'm missing.
The fact is that I can get the PHP CLI working in our production server. However I need to test a process prior to be automated, and there is no way to get it working as expected in the CLI of the development server.
It simply outputs nothing. But no error is displayed either. Even if it's the index.php page, when I do this in the prod. server, the CLI displays the final html. The same index.php displays nothing.
Any suggestions please?
Off hand I can't think why you would get no output. Does something simple from the command line work, like:
php -r "echo 'Hello, world.'";
PS: Just in case, we are talking CLI (command line interface) here and not CGI, right?
a simple echo like that works perfectly (I was talking about the command line interface). That's what keeps me more puzzled.
What might be stopping it to output anything when I run code from a file?
BTW: there is no output because the process is not executed. It must update some data in the DB and create a log, and none of these actions happen.
Last edited by Jazztronik; 06-20-2012 at 01:52 AM.
How are you executing the script? I ran into some issues migrating some CLI scripts from XP to Windows 7 and found that the way paths were determined from cmd.exe had altered a bit (as well as the "default" actions for executables).
Originally Posted by Jazztronik
well I'm using Linux, and absolute paths so that the execution is not affected by the directory from which the execution takes place. Something like this (I'm using codeigniter and this is the way to execute scripts with it):
php /absolute/path/to/script/index.php controller_name method_name parameter1 parameter2
The only CLI gotcha I can think of I've run into lately (the last year or so) is that in one instance I had to be sure to cd to the directory of the script I was invoking, as it was calling other scripts relative to its current working directory.
Another thing to check is if it's using a different php.ini file than you think it is (the CLI can potentially use a different one than the ISAPI or other web interface does).
Is that in accordance with what's here: http://codeigniter.com/user_guide/general/cli.html ? (I've not looked at it closely, I just know it exists. )
Originally Posted by Jazztronik
that's right. The CodeIgniter documentation in which I learnt how to invoke a controller method with some parameter.
Since it worked perfectly in production with absolute paths I assumed it had to behave the same in development. Anyway, tomorrow in the office I will try to execute it just from the same directory as index.php, just in case that's the problem.
To be continued....
Just tried moving to the script path and executing
php index.php controller method param
and it still does nothing.
Just when I enter the command, in less than a second the command prompt appears again.
Can you run "php -v" to make sure you are able to execute CLI at all?
Or php -l filename.php to see if anything interesting shows up in terms of errors? (That's a lower-case "L", not at number "1".)
Hello again mates.
This is what I get when running what you said:
[root@pool-100-0-7-225 ~]# php -v
PHP 5.3.8 (cli) (built: Nov 8 2011 13:54:44)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
[root@pool-100-0-7-225 ~]# php -l /path/to/web/index.php
No syntax errors detected in /path/to/web/index.php
[root@pool-100-0-7-225 web]# php -l index.php
No syntax errors detected in index.php
The CLI is installed, and no syntax error is detected. Anyway, it worked in production and no error was raised.
Is it having trouble determining if it was a CLI call? Could be a mini-logic error as well. Is the exact same script running in production? Is the file permissions the same as production (for the user executing the script)?
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread