Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Can we use PHP from the command line?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #2  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #3  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #4  
Old 03-02-2010
Member
 
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
Reply With Quote
  #5  
Old 03-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #6  
Old 03-02-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Can we use PHP from the command line?"
Thread Thread Starter Forum Replies Last Post
xcopy command line together with wmplayer command line Aislinn Operating Systems 5 31-03-2010 12:13 PM
Problem: Command Line Option Syntax Error. Type Command /? For Help Nadeem MediaCenter 3 03-09-2009 05:41 PM
Command Line Ren (Rename) command broken? SixSigmaGuy Vista Help 2 18-05-2008 03:30 PM
Run MSI from Command Line Thomas M. Windows Security 2 03-11-2007 03:49 AM
autorun.inf - shell\..\command with command line parameter doesn'twork kakii Windows XP Support 1 18-05-2007 01:24 AM


All times are GMT +5.5. The time now is 09:19 AM.