How to run php files using cmd

小云云
Release: 2023-03-22 21:36:01
Original
5099 people have browsed it

This article mainly shares with you how cmd runs php files, and shares the principle of how cmd runs php files. I hope it can help everyone.

Configure php environment variables:

1. Find the path to php such as "D:/php". If it is not installed, you can download it from the official website http://www.php.net /downloads.php.
2. You need to ensure that the configuration of php.ini in this directory is correct. If it is a php package you just downloaded, you may need to modify some corresponding configurations: change the name of "php.ini-development" in the php directory. For: php.ini (the specific configuration method of php.ini will not be described in detail).
3. Right-click "My Computer"->"Properties"->Select the "Advanced" tab->Click "Environment Variables"->Click "Path" in the "System Variables" list below ->Click "Edit" below->Add "D:/php;D:/php/ext;" at the beginning of "Variable Value"->Confirm.
4. Click the "New" button in front of the "Edit" button of the system variable ->Enter "PHPRC" after "Variable Name" ->Enter "D:phpP" for "Variable Value" ->Confirm
5. Restart
6. Use the php -h command in the Windows command line to test whether the environment variables are configured correctly and php can run successfully.

Run the php file:

1. After configuring the environment variables, open cmd and enter the directory where the php file is located

Then you can directly execute the php script

For example: php test.php

Solution to PHP script execution timeout:
PHP default script execution timeout is 30 seconds, which is specified by the max_execution_time variable in php.ini. The server will wait for 30 seconds. Forcibly terminate the executing program after seconds. If you want to finish executing a script that takes more than 30 seconds, you can solve it through the following methods:
(1) Modify the script execution time limit of php.ini
Edit php .ini, modify the max_execution_time value:
max_execution_time=500
//This modification requires reloading php.ini and restarting the web server to take effect.
(2) Set the script execution time through the .htaccess file
php_value max_execution_time 500
(3) Set the maximum execution time in the script
ini_set('max_execution_time', 500);
( 4) Use the PHP function to cancel the time limit of the script
set_time_limit(0);
set_time_limit is used to set the timeout time of the script. This function stipulates that the program must be completed within the specified number of seconds from the time the sentence is run. If timeout occurs, the program exits with an error.
Usage: set_time_limit(seconds);
//When the seconds is 0, it indicates that the script has no time limit.

cmd runs the php file with parameters

cmd runs the php file with parameters:

space + parameter after the php file
Use $argv[] in the program Reading parameters

$argv is an array including all passed parameters and is a predefined variable of PHP

Use $argc in the program to read the number of parameters

Example:

php -q D:\php5_site\s.php http://www.baidu.com

<span style="font-family:SimSun;font-size:18px;"><?php
$url = $argv[1];
echo $url;
?>
</span>
Copy after login

Related recommendations:

How to configure PHPStorm to run PHP projects

thinkPHP cli command running PHP code example

Configuration file for running PHP framework Laravel in Nginx

The above is the detailed content of How to run php files using cmd. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!