---
title: "How can I execute a PHP script using command line?"  
description: "How can I execute a PHP script using command line?"  
author: "Rajesh Goswami"  
published: 2010-10-19  
updated: 2020-09-22  
canonical: https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# How can I execute a PHP script using command line?

We can execute the php script on command line \
php filename.You can easily parse command line arguments into the $_GET variable by using the parse_str() function.\
\

```
<?phpparse_str(implode('&', array_slice($argv, 1)), $_GET);?>
```

## Answers

### Answer by Amrita Bhattacharjee

The following steps are required for executing PHP script using Command Line-

1.Create a PHP file and you can follow the following one:\
file_name.php, pr1.php

2.Open command prompt to change the directory into the folder containing the PHP files you created.

3.Enter the following command into command prompt to run the script file which you created and as an example the following can be followed based on the name of the file which is used here as example:

D:\php_project\php pr1.php

### Answer by Anonymous User

We can execute the php script on command line \
php filename.You can easily parse command line arguments into the $_GET variable by using the parse_str() function.\
\

```
<?phpparse_str(implode('&', array_slice($argv, 1)), $_GET);?>
```


---

Original Source: https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
