Reputation: 667
I just found two executable files, php-cgi.exe
and php.exe
in the bin
folder of the WAMP server on my laptop. I am learning PHP and could not figure out the difference. What is difference between them?
Upvotes: 61
Views: 77279
Reputation: 25
A little excerpt from an article I am writing entitled Understanding PHP...
/usr/lib64/httpd/modules/libphp5.so
The actual file name of the Apache-specific PHP Interpreter that is typically loaded into the modular Apache System, thus enabling it to interpret PHP scripts.
/usr/bin/php
A PHP Interpreter intended for stand-alone PHP applications invoked via the command line. This interpreter helps to position PHP as a Web Server independent general-purpose programming or scripting language.
/usr/bin/php-cgi
A Common Gateway Interface PHP Interpreter intended for receiving PHP scripts via the agency of a Web Server. This is the original implementation methodology of PHP, and it is mostly a legacy thing considering that other CGI approaches (such as FastCGI and php-fpm) offer better performance. Therefore, php-cgi should only be used as a last resort, when no other better performing options are available.
Upvotes: 1
Reputation: 31130
This might give you a broader understanding of their difference:
CGI: (common gateway interface) It is a specification "protocol" for transferring information between a Web server and a CGI program.
A CGI program is any program designed to accept and return data that conforms to the CGI specification.
Basically it's a way to run a server side script (PHP, Perl, Python,...) when a HTTP request comes.
CGI is very slow in comparison to other alternatives.
FastCGI: is a better CGI.
Fast CGI is a different approach with much faster results.
It is a CGI with only a few extensions.
FastCGI implementation isn’t available anymore, in favor of the PHP-FPM.
PHP-FPM: (FastCGI Process Manager), it's a better FastCGI implementation than the old FastCGI.
It runs as a standalone FastCGI server.
In general it's a PHP interface for the web servers (Apache, Nginx..) to allows Web Server to interact with PHP.
Unlike the PHP-CLI which is a command line interface for PHP to allows Users to interact with PHP via terminal.
mod_php: an Apache module to run PHP.
It execute PHP scripts inside the Web Server directly as part of the web server without communicating with a CGI program.
mod_SuPHP: is similar to mod_php but can change the user/group that the process runs under.
Basically it address some problems of mod_php related to permissions.
Upvotes: 62
Reputation: 1411
From http://www.php-cli.com/php-cli-cgi.shtml
These are the most important differences between CLI and CGI:
Upvotes: 66
Reputation: 88796
php-cli
is meant for running PHP on the command line. php-cgi
does additional things for you, such as HTTP headers and certain security modifications.
Having said that, consider installing a FastCGI module and using PHP's FastCGI interface. This should run PHP noticably faster than php-cgi. I believe the standard Apache FastCGI module is mod_fcgid
.
Upvotes: 8
Reputation: 324650
php-cgi
is intended for a webserver. Among other things it handles HTTP headers for you.
The CLI version is intended to run on a command line (hence "Command Line Interface"). This one does not handle headers, or any other server-related things.
Upvotes: 18
Reputation: 19635
PHP CLI is the command-line interface for PHP (e.g. for creating standalone applications)
PHP CGI is the common gateway interface for PHP (e.g. for web applications)
Upvotes: 24