CL PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joshua Beall

    CL PHP

    Hi All,

    I am trying to do some command line PHP, and I note that when I type 'php'
    and hit enter, it does start up PHP. But how do I get it to do anything?
    'man php' says that "If no parameter is present then the standard input is
    read and executed." But I cannot get to execute anything - either that or I
    am not seeing the output.

    I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
    actually execute. Any pointers?

    Sincerely,
    -Josh


  • J.O. Aho

    #2
    Re: CL PHP

    Joshua Beall wrote:[color=blue]
    > Hi All,
    >
    > I am trying to do some command line PHP, and I note that when I type 'php'
    > and hit enter, it does start up PHP. But how do I get it to do anything?
    > 'man php' says that "If no parameter is present then the standard input is
    > read and executed." But I cannot get to execute anything - either that or I
    > am not seeing the output.
    >
    > I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
    > actually execute. Any pointers?[/color]

    php myfile.php


    //Aho

    Comment

    • Kevin Thorpe

      #3
      Re: CL PHP

      Joshua Beall wrote:[color=blue]
      > Hi All,
      >
      > I am trying to do some command line PHP, and I note that when I type 'php'
      > and hit enter, it does start up PHP. But how do I get it to do anything?
      > 'man php' says that "If no parameter is present then the standard input is
      > read and executed." But I cannot get to execute anything - either that or I
      > am not seeing the output.
      >
      > I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
      > actually execute. Any pointers?[/color]

      Should work, it does for me. Run php then type your script (remember the
      <?php ?> tags) then ctrl-d.

      Alternatively: php < script.php
      or: php script.php

      add -q to stop the header appearing

      Comment

      • Joshua Beall

        #4
        Re: CL PHP

        "Kevin Thorpe" <kevin@pricetra k.com> wrote in message
        news:4044a2e1$0 $2631$afc38c87@ news.easynet.co .uk...[color=blue]
        > Should work, it does for me. Run php then type your script (remember the
        > <?php ?> tags) then ctrl-d.[/color]

        Hmm... I have to hit ctrl-d twice.

        Why?


        Comment

        • Joshua Beall

          #5
          Re: CL PHP

          "J.O. Aho" <user@example.n et> wrote in message
          news:c226s6$1ob eke$1@ID-130698.news.uni-berlin.de...[color=blue][color=green]
          > > I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
          > > actually execute. Any pointers?[/color]
          >
          > php myfile.php[/color]

          I know that, I am trying to get it to read from the stdin, not a file


          Comment

          • Mark Kuiphuis

            #6
            Re: CL PHP

            Add php.exe to your PATH variable. Then go to a directory where a
            php-file is stored. Then execute this file using the command:

            php filename.php

            if php.exe (for windows) or the php binary (on UNIX-like systems) isn't
            available in your path you can execute as follows (assuming you are in
            the folder where the php executable is located)

            php /link/to/filename.php

            Have fun!! :)

            Mark

            Joshua Beall wrote:[color=blue]
            > Hi All,
            >
            > I am trying to do some command line PHP, and I note that when I type 'php'
            > and hit enter, it does start up PHP. But how do I get it to do anything?
            > 'man php' says that "If no parameter is present then the standard input is
            > read and executed." But I cannot get to execute anything - either that or I
            > am not seeing the output.
            >
            > I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
            > actually execute. Any pointers?
            >
            > Sincerely,
            > -Josh
            >
            >[/color]

            Comment

            • Kevin Thorpe

              #7
              Re: CL PHP

              Joshua Beall wrote:
              [color=blue]
              > "J.O. Aho" <user@example.n et> wrote in message
              > news:c226s6$1ob eke$1@ID-130698.news.uni-berlin.de...
              >[color=green][color=darkred]
              >>>I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
              >>>actually execute. Any pointers?[/color]
              >>
              >>php myfile.php[/color]
              >
              >
              > I know that, I am trying to get it to read from the stdin, not a file
              >[/color]
              'cat script.php|php' works just fine

              Comment

              • Alvaro G Vicario

                #8
                Re: CL PHP

                *** Joshua Beall wrote/escribió (Tue, 02 Mar 2004 14:41:39 GMT):[color=blue]
                > I am trying to do some command line PHP, and I note that when I type 'php'
                > and hit enter, it does start up PHP. But how do I get it to do anything?[/color]

                Just type. It's waiting for some code. Type Ctrl+D when finished:

                # php
                <?
                echo 'Hi!';
                ?>
                X-Powered-By: PHP/4.2.2
                Content-type: text/html

                Hi!


                You can also use the typical shell tricks to redirect standard input:

                cat source_file | php
                php < source_file

                Last but not least, you add use parameter:

                php source_file



                P.S. This is in Unix, in Windows it should work similarly.

                --
                --
                -- Álvaro G. Vicario - Burgos, Spain
                --

                Comment

                • Mike Peters

                  #9
                  Re: CL PHP

                  On 2004-03-02, Joshua Beall wrote:[color=blue]
                  > Hi All,
                  >
                  > I am trying to do some command line PHP, and I note that when I type 'php'
                  > and hit enter, it does start up PHP. But how do I get it to do anything?
                  > 'man php' says that "If no parameter is present then the standard input is
                  > read and executed." But I cannot get to execute anything - either that or I
                  > am not seeing the output.
                  >
                  > I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
                  > actually execute. Any pointers?
                  >
                  > Sincerely,
                  > -Josh
                  >[/color]

                  You need to enclose your code in <?php and ?> and it seems ctrl-dd works
                  for me.

                  --
                  Mike Peters
                  mike [-AT-] ice2o [-DOT-] com
                  I am a DevOps and Cloud architecture consultant based in Northumberland in the UK. I provide consultancy on DevOps and private and public cloud solutions. I design and implement continous integration and continuous delivery solutions using Open Source, bespoke and commercial off the shelf software. I can also provide training and tuition for you or your team in DevOps best practices, tooling and solutions, OpenSource software, automation and cloud architecture solutions.

                  Comment

                  • Joshua Beall

                    #10
                    Re: CL PHP

                    "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
                    message news:dnvc4pu90v 8e.1eogi3x72p05 j.dlg@40tude.ne t...[color=blue]
                    > Just type. It's waiting for some code. Type Ctrl+D when finished:[/color]

                    Hmm... I have to hit ctrl-d twice.

                    Why?


                    Comment

                    • Joshua Beall

                      #11
                      Re: CL PHP

                      "Mike Peters" <o0__mike__0oRE MOVE@THIShotmai l.com> wrote in message
                      news:e834c3f387 f6c3375771d7569 b2fc388@news.te ranews.com...[color=blue]
                      > You need to enclose your code in <?php and ?> and it seems ctrl-dd works
                      > for me.[/color]

                      Hmm... I have to hit ctrl-d twice.

                      Why?


                      Comment

                      • CountScubula

                        #12
                        Re: CL PHP

                        "Joshua Beall" <jbeall@donotsp am.remove.me.he raldic.us> wrote in message
                        news:D211c.1251 4$rW6.2218@nwrd dc03.gnilink.ne t...[color=blue]
                        > Hi All,
                        >
                        > I am trying to do some command line PHP, and I note that when I type 'php'
                        > and hit enter, it does start up PHP. But how do I get it to do anything?
                        > 'man php' says that "If no parameter is present then the standard input is
                        > read and executed." But I cannot get to execute anything - either that or[/color]
                        I[color=blue]
                        > am not seeing the output.
                        >
                        > I have tried ctrl-d, ctrl-c, and ctrl-z. None of them seem to get it to
                        > actually execute. Any pointers?
                        >
                        > Sincerely,
                        > -Josh
                        >
                        >[/color]

                        Just typing php will start php, and wait for you to type a script.

                        To run a php script do this:

                        php -q myscriptname.ph p

                        the -q will supress headers, try without it to see what I am talking about


                        --
                        Mike Bradley
                        http://www.gzentools.com -- free online php tools


                        Comment

                        • Mike Peters

                          #13
                          Re: CL PHP

                          On 2004-03-02, Joshua Beall wrote:[color=blue]
                          > "Mike Peters" <o0__mike__0oRE MOVE@THIShotmai l.com> wrote in message
                          > news:e834c3f387 f6c3375771d7569 b2fc388@news.te ranews.com...[color=green]
                          >> You need to enclose your code in <?php and ?> and it seems ctrl-dd works
                          >> for me.[/color]
                          >
                          > Hmm... I have to hit ctrl-d twice.
                          >
                          > Why?
                          >[/color]
                          I think, although I'm not sure, that the first ctrl-d parses the code
                          and the second executes it. At least trying with erroneous code, hitting
                          ctrl-d once causes the shell to exit with a parse error.

                          In fact after some experimentation , it seems that the above is the case
                          if you use php on it's own, but upon running php -a, you only need to
                          hit ctrl-d once and you stay in the shell once the code is executed,
                          hitting ctrl-d twice executes the code and closes the shell.

                          HTH
                          --
                          Mike Peters
                          mike [-AT-] ice2o [-DOT-] com
                          I am a DevOps and Cloud architecture consultant based in Northumberland in the UK. I provide consultancy on DevOps and private and public cloud solutions. I design and implement continous integration and continuous delivery solutions using Open Source, bespoke and commercial off the shelf software. I can also provide training and tuition for you or your team in DevOps best practices, tooling and solutions, OpenSource software, automation and cloud architecture solutions.

                          Comment

                          • Joshua Beall

                            #14
                            Re: CL PHP

                            "Mike Peters" <o0__mike__0oRE MOVE@THIShotmai l.com> wrote in message
                            news:04475d800e a18abfb12d2f61d 065861d@news.te ranews.com...[color=blue]
                            > On 2004-03-02, Joshua Beall wrote:[color=green]
                            > > "Mike Peters" <o0__mike__0oRE MOVE@THIShotmai l.com> wrote in message
                            > > news:e834c3f387 f6c3375771d7569 b2fc388@news.te ranews.com...[color=darkred]
                            > >> You need to enclose your code in <?php and ?> and it seems ctrl-dd[/color][/color][/color]
                            works[color=blue][color=green][color=darkred]
                            > >> for me.[/color]
                            > >
                            > > Hmm... I have to hit ctrl-d twice.
                            > >
                            > > Why?
                            > >[/color]
                            > I think, although I'm not sure, that the first ctrl-d parses the code
                            > and the second executes it. At least trying with erroneous code, hitting
                            > ctrl-d once causes the shell to exit with a parse error.[/color]

                            Interesting. BTW, thanks for actually reading my question before
                            responding, I think a half dozen people have posted here saying "just run
                            'php filename.php' to execute a script."

                            Guess you cannot complain too much about free help though :-)

                            Thanks!

                            -Josh


                            Comment

                            • J Taylor

                              #15
                              Re: CL PHP

                              Ok, from the *nux world, there are two possibilities - the first is to
                              both chmod +x the file and then add a shebang line (#! /usr/bin/php4) to
                              the top of the script, then you can run it.

                              Or you can just type php4 scriptname and that should run it. You will
                              need to have the php4 cgi version installed not the apache version.

                              Its quite possible that you can just call php4 and then start typing a
                              script into it <? blah blah ?> but I dont know for sure.

                              Its also possible to write a generic script container that uses console
                              tools such as ob and then evals each line as it is typed, possibly
                              catching on for words or characters to trigger the eval stage.

                              J

                              Comment

                              Working...