Results 1 to 6 of 6

Thread: Can we use PHP from the command line?

  1. #1
    Join Date
    Jul 2006
    Posts
    442

    Can we use PHP from the command line?

    I am not having much knowledge about the PHP. I have done with the basic programs in PHP but when it comes to somewhat advanced I am rookie. I have never used the command line for the PHP. One thing that always comes in my mind is can we use PHP from the command line?. And also please tell me what does it contains.?? Help me as soon as possible..!!
    "When they give you ruled paper, write the other way..." J.R.J.

  2. #2
    Join Date
    Mar 2008
    Posts
    349

    Re: Can we use PHP from the command line?

    According to me for developing the web applications rapidly and economically, PHP is a great language. Script like c, c++, java, etc the PHP can also be run as a command line. There are many other tasks that need to be run on the background in the web server, other than the building web applications and websites which takes lot of time. You can create command line PHP script as we do for web script. You can use the command
    Code:
    php -h
    for the help in PHP. By using this command, you will get an idea of using the other basic commands.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Can we use PHP from the command line?

    The SAPI is supported by the PHP. The main focus of this SAPI is for developing shell applications with PHP. Typing php -v, in the shell application will let you know whether php you are using is CGI or CLI. In a command line scripting, you cannot use any kind of HTML tags. The reason behind this is that the output is displaying in the DOS prompt and not in the web browser. You cannot use the <BR> tag for inserting new line in the command line scripting instead of that you will have to use the \n to output the new line. Hope that you are clear with the concepts of the command line which is being used in PHP.

  4. #4
    Join Date
    Jul 2006
    Posts
    289

    Re: Can we use PHP from the command line?

    You can understand more better if you look at the examples below. I have given a small command line script to output “Hello World”. The following is the code for that :
    PHP Code:
    <?php
    print "Hello World!";
    ?>
    Your filename would be helloworld.php
    Now if you want to execute the above script in command prompt or the shell prompt, you will have to type the following command :
    Code:
    php helloworld.php
    Signatures reduce available bandwidth

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Can we use PHP from the command line?

    If you want to run a phpfile directly, the only thing you will have to type the command php filename.php. This is the simplest use of PHP command line mode. You will have to make some changes in your setups in to your running environment, which should be done otherwise there will be some errors. The following are the list of the changes that should be done :
    1. The first change that you would have to do is to put the folder containing the php.exe on the path. If you are using the Windows then the path is : c:\phpfolder;%Path%.
    2. Then make the copy of the php.ini file. After making the copy store it in this directory/folder;
    3. Lastly make the following changes to the php.ini file :
      • implicit_flush=on
      • output_buffering=off
      • max_execution_time = 30000.

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Can we use PHP from the command line?

    I am going little deep, which can help you in future. You can use the standard output stream defined in CLI version of the PHP, instead of using print or echo for output that we normally use. There are three IO streams in PHP, which are described as follows :
    • php://stdin (read)
    • php://stderr (write)
    • php://stdout (write)

    These streams are defined as constants namely STDIN, STDERR AND STDOUT from PHP. Hope that this helps you little bit.

Similar Threads

  1. xcopy command line together with wmplayer command line
    By Aislinn in forum Operating Systems
    Replies: 5
    Last Post: 31-03-2010, 12:13 PM
  2. Replies: 3
    Last Post: 03-09-2009, 05:41 PM
  3. Command Line Ren (Rename) command broken?
    By SixSigmaGuy in forum Vista Help
    Replies: 2
    Last Post: 18-05-2008, 03:30 PM
  4. Run MSI from Command Line
    By Thomas M. in forum Windows Security
    Replies: 2
    Last Post: 03-11-2007, 03:49 AM
  5. Replies: 1
    Last Post: 18-05-2007, 01:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,135,371.99086 seconds with 17 queries