Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


How Can I use command line in PHP?

  • Please log in to reply
1 reply to this topic

#1 rajesh01


  • Banned Spammer
  • 3 posts
  • Local time:07:41 AM

Posted 14 March 2015 - 05:30 AM

Hi all


This the question ask to me while giving the interview of PHP developer. There are many PHP development companies in delhi. But going for interviews in top most companies they ask many difficult question. So if any one having suggestions please reply me.



BC AdBot (Login to Remove)


#2 matt_tty0


  • Members
  • 5 posts
  • Gender:Male
  • Location:Cleveland Ohio
  • Local time:10:11 PM

Posted 11 April 2015 - 01:01 AM

You can use the php exec() function to execute a command line program.


You can read about it here:



I have used exec() to invoke the python interpreter, which then runs a python script that calculates an interest rate for a loan.

The value from the python script is returned to php and stored in a variable.


An example of the PHP exec() function used in PHP code:

$var = exec("python Newton.py $this->N $this->PV $this->PMT $this->FV $this->K 2>&1");

Here are some other related php functions of interest:

  • eval() interprets as php code
  • preg_replace() with /e modifier interprets as php code
    • this is superceded, now use: preg_replace_callback()
  • exec() runs execs and scripts
  • passthru() runs a command returns output to browser
  • backticks (like it works in a bash script) execs command
  • system() like passthru without binary data
  • popen() exec command and connects pipes to file descriptor
  • fopen() opens with file handle
  • readfile() opens and writes to browser
  • file() reads file to an array

A very well written book that covers just about everything is: PHP 5 Power Programming, Prentice Hall, by Gutmans, Bakken, and Rethans.


I use the chm format of the php manual for detailed references:





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users