www.webdeveloper.com
Results 1 to 13 of 13

Thread: No output using PHP CLI

  1. #1
    Join Date
    Jul 2007
    Posts
    245

    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?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,925
    Off hand I can't think why you would get no output. Does something simple from the command line work, like:
    Code:
    php -r "echo 'Hello, world.'";
    ?

    PS: Just in case, we are talking CLI (command line interface) here and not CGI, right?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2007
    Posts
    245
    Hi NogDog,

    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.

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by Jazztronik View Post
    Hi NogDog,

    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.
    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).

  5. #5
    Join Date
    Jul 2007
    Posts
    245
    Hi Criterion9,

    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

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,925
    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).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,925
    Quote Originally Posted by Jazztronik View Post
    Hi Criterion9,

    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
    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. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  8. #8
    Join Date
    Jul 2007
    Posts
    245
    Hi NogDog,

    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....

  9. #9
    Join Date
    Jul 2007
    Posts
    245
    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.

  10. #10
    Join Date
    Jan 2009
    Posts
    3,346
    Can you run "php -v" to make sure you are able to execute CLI at all?

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,925
    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".)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Jul 2007
    Posts
    245
    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 ~]#

    [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 ~]#

    [root@pool-100-0-7-225 web]# php -l index.php
    No syntax errors detected in index.php
    [root@pool-100-0-7-225 web]#

    The CLI is installed, and no syntax error is detected. Anyway, it worked in production and no error was raised.

  13. #13
    Join Date
    Jan 2009
    Posts
    3,346
    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)?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles