PHP
Encyclopedia
PHP is a general-purpose server-side scripting language
Scripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...

 originally designed for web development
Web development
Web development is a broad term for the work involved in developing a web site for the Internet or an intranet . This can include web design, web content development, client liaison, client-side/server-side scripting, web server and network security configuration, and e-commerce development...

 to produce dynamic web page
Dynamic web page
A dynamic web page is a kind of web page that has been prepared with fresh information , for each individual viewing. It is not static because it changes with the time , the user , the user interaction , the context A dynamic web page is a kind of web page that has been prepared with fresh...

s. For this purpose, PHP code is embedded into the HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

 source document and interpreted by a web server
Web server
Web server can refer to either the hardware or the software that helps to deliver content that can be accessed through the Internet....

 with a PHP processor module, which generates the web page
Web page
A web page or webpage is a document or information resource that is suitable for the World Wide Web and can be accessed through a web browser and displayed on a monitor or mobile device. This information is usually in HTML or XHTML format, and may provide navigation to other web pages via hypertext...

 document. It also has evolved to include a command-line interface
Command-line interface
A command-line interface is a mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks...

 capability and can be used in standalone graphical applications
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

. PHP can be deployed on most web servers and as a standalone interpreter, on almost every operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

 and platform
Platform (computing)
A computing platform includes some sort of hardware architecture and a software framework , where the combination allows software, particularly application software, to run...

 free of charge. There is also commercial software such as RadPHP, a rapid application development
Rapid application development
Rapid application development is a software development methodology that uses minimal planning in favor of rapid prototyping. The "planning" of software developed using RAD is interleaved with writing the software itself...

 framework
Software framework
In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by user code, thus providing application specific software...

 for the PHP language. A competitor to Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

's Active Server Pages
Active Server Pages
Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated Web pages. Initially released as an add-on to Internet Information Services via the Windows NT 4.0 Option Pack Active Server Pages (ASP), also known as Classic...

 (ASP) server-side script engine and similar languages, PHP is installed on more than 20 million websites and 1 million web server
Web server
Web server can refer to either the hardware or the software that helps to deliver content that can be accessed through the Internet....

s.

PHP was originally created by Rasmus Lerdorf
Rasmus Lerdorf
Rasmus Lerdorf is a Danish programmer with Canadian citizenship and is most notable as the creator of the PHP scripting language. He authored the first two versions...

 in 1995. The main implementation of PHP is now produced by The PHP Group and serves as the de facto standard
De facto standard
A de facto standard is a custom, convention, product, or system that has achieved a dominant position by public acceptance or market forces...

 for PHP as there is no formal specification
Formal specification
In computer science, a formal specification is a mathematical description of software or hardware that may be used to develop an implementation. It describes what the system should do, not how the system should do it...

. PHP is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 released under the PHP License
PHP License
The PHP License is the software license under which the PHP scripting language is released. The PHP License is a non-copyleft free software license according to the Free Software Foundation and an open source license according to the Open Source Initiative...

 which is incompatible with the GNU General Public License
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

 (GPL) due to restrictions on the usage of the term PHP.

While PHP originally stood for "Personal Home Page", it is now said to stand for "PHP: Hypertext Preprocessor", a recursive acronym
Recursive acronym
A recursive acronym is an acronym or initialism that refers to itself in the expression for which it stands...

.

History

PHP development began in 1994 when the Danish/Greenland
Greenland
Greenland is an autonomous country within the Kingdom of Denmark, located between the Arctic and Atlantic Oceans, east of the Canadian Arctic Archipelago. Though physiographically a part of the continent of North America, Greenland has been politically and culturally associated with Europe for...

ic/Canadian
Canada
Canada is a North American country consisting of ten provinces and three territories. Located in the northern part of the continent, it extends from the Atlantic Ocean in the east to the Pacific Ocean in the west, and northward into the Arctic Ocean...

 programmer Rasmus Lerdorf
Rasmus Lerdorf
Rasmus Lerdorf is a Danish programmer with Canadian citizenship and is most notable as the creator of the PHP scripting language. He authored the first two versions...

 initially created a set of Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

 scripts he called "Personal Home Page Tools" to maintain his personal homepage. The scripts performed tasks such as displaying his résumé and recording his web-page traffic
Web traffic
Web traffic is the amount of data sent and received by visitors to a web site. It is a large portion of Internet traffic. This is determined by the number of visitors and the number of pages they visit...

. Lerdorf initially announced the release of PHP on the comp.infosystems.www.authoring.cgi Usenet
Usenet
Usenet is a worldwide distributed Internet discussion system. It developed from the general purpose UUCP architecture of the same name.Duke University graduate students Tom Truscott and Jim Ellis conceived the idea in 1979 and it was established in 1980...

 discussion group on June 8, 1995.

Zeev Suraski
Zeev Suraski
Zeev Suraski is an Israeli programmer, PHP developer and co-founder of Zend Technologies. A graduate of the Technion in Haifa, Israel, Suraski and fellow student Andi Gutmans created PHP 3 in 1997. In 1999 they wrote the Zend Engine, the core of PHP 4, and founded Zend Technologies, which has...

 and Andi Gutmans
Andi Gutmans
Andi Gutmans is an Israeli programmer with Swiss roots, PHP developer and co-founder of Zend Technologies. A graduate of the Technion, the Israel Institute of Technology in Haifa, Gutmans and fellow student Zeev Suraski created PHP 3 in 1997...

, two Israel
Israel
The State of Israel is a parliamentary republic located in the Middle East, along the eastern shore of the Mediterranean Sea...

i developers at the Technion IIT, rewrote the parser in 1997 and formed the base of PHP 3, changing the language's name to the recursive initialism PHP: Hypertext Preprocessor. Afterwards, public testing of PHP 3 began, and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite
Rewrite (programming)
A rewrite in computer programming is the act or result of re-implementing a large portion of existing functionality without re-use of its source code. When the rewrite is not using existing code at all, it is common to speak of a rewrite from scratch...

 of PHP's core, producing the Zend Engine
Zend engine
The Zend Engine is an open source scripting engine , commonly known for the important role it plays in the web automation language PHP. It was originally developed by Andi Gutmans and Zeev Suraski while they were students at the Technion - Israel Institute of Technology. They later founded a...

 in 1999. They also founded Zend Technologies
Zend Technologies
Zend Technologies Ltd. is an Israeli world wide web infrastructure software company with headquarters in Cupertino, California, U.S., technology center in Ramat Gan, Tel Aviv, Israel and offices in France, Italy and Germany...

 in Ramat Gan, Israel.

In 2008 PHP 5 became the only stable version under development. Late static binding had been missing from PHP and was added in version 5.3.

A new major version has been under development alongside PHP 5 for several years. This version was originally planned to be released as PHP 6 as a result of its significant changes, which included plans for full Unicode support. However, Unicode support took developers much longer to implement than originally thought, and the decision was made in March 2010 to move the project to a branch, with features still under development moved to trunk
Trunk (software)
In the field of software development, trunk refers to the unnamed branch of a file tree under revision control. The trunk is usually meant to be the base of a project on which development progresses. If developers are working exclusively on the trunk, it always contains the latest cutting-edge...

.

Changes in the new code include the removal of register_globals, magic quotes
Magic quotes
Magic quotes is a controversial feature of the PHP scripting language, which was introduced to help newcomers write functioning SQL commands without requiring manual escaping. It was later described and widely misinterpreted as help to prevent inexperienced developers from writing code which is...

, and safe mode. The reason for the removals was that register_globals had opened security holes by intentionally allowing runtime data injection, and the use of magic quotes had an unpredictable nature. Instead, to escape characters, magic quotes may be replaced with the addslashes function, or more appropriately an escape mechanism specific to the database vendor itself like mysql_real_escape_string for MySQL
MySQL
MySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...

. Functions that will be removed in future versions and have been deprecated in PHP 5.3 will produce a warning if used.

Many high-profile open-source projects ceased to support PHP 4 in new code as of February 5, 2008, because of the GoPHP5 initiative, provided by a consortium of PHP developers promoting the transition from PHP 4 to PHP 5.

PHP does not have native support for Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

 or multibyte strings; Unicode support is under development for a future version of PHP and will allow strings as well as class-, method-, and function-names to contain non-ASCII
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

 characters.

PHP interpreters are available on both 32-bit
32-bit
The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory....

 and 64-bit
64-bit
64-bit is a word size that defines certain classes of computer architecture, buses, memory and CPUs, and by extension the software that runs on them. 64-bit CPUs have existed in supercomputers since the 1970s and in RISC-based workstations and servers since the early 1990s...

 operating systems, but on Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 the only official distribution is a 32-bit implementation, requiring Windows 32-bit compatibility mode while using Internet Information Services
Internet Information Services
Internet Information Services – formerly called Internet Information Server – is a web server application and set of feature extension modules created by Microsoft for use with Microsoft Windows. It is the most used web server after Apache HTTP Server. IIS 7.5 supports HTTP, HTTPS,...

 (IIS) on a 64-bit Windows platform. Experimental 64-bit versions of PHP 5.3.0 were briefly available for MS Windows, but have since been removed.

Licensing

PHP is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 released under the PHP License
PHP License
The PHP License is the software license under which the PHP scripting language is released. The PHP License is a non-copyleft free software license according to the Free Software Foundation and an open source license according to the Open Source Initiative...

, which insists that:
4. Products derived from this software may not be called "PHP", nor
may "PHP" appear in their name, without prior written permission
from group@php.net. You may indicate that your software works in
conjunction with PHP by saying "Foo for PHP" instead of calling
it "PHP Foo" or "phpfoo"

This restriction on use of the name PHP makes it incompatible with the GNU General Public License
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

 (GPL).

Release history

Meaning
Red Release no longer supported
Green Release still supported
Blue Future release


Major version Minor version Release date Notes
1 1.0.0 Officially called "Personal Home Page Tools (PHP Tools)". This is the first use of the name "PHP".
2 2.0.0 Considered by its creator as the "fastest and simplest tool" for creating dynamic web pages.
3 3.0.0 Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewrite the base for this version.
3.0.18 The latest release for PHP 3.0.x. Unsupported Historical Releases
4 4.0.0 Added more advanced two-stage parse/execute tag-parsing system called the Zend engine.
4.1.0 Introduced 'superglobals' ($_GET, $_POST, $_SESSION, etc.)
4.2.0 Disabled register_globals by default. Data received over the network is not inserted directly into the global
Global variable
In computer programming, a global variable is a variable that is accessible in every scope . Interaction mechanisms with global variables are called global environment mechanisms...

 namespace anymore, closing possible security holes in applications.
4.3.0 Introduced the CLI
Command-line interface
A command-line interface is a mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks...

, in addition to the CGI
Common Gateway Interface
The Common Gateway Interface is a standard method for web servers software to delegate the generation of web pages to executable files...

.
4.4.0 Added man pages for phpize and php-config scripts.
4.4.9 Security enhancements and bug fixes. The last release of the PHP 4.4 series.
5 5.0.0 Zend Engine II with a new object model.
5.1.0 Performance improvements with introduction of compiler variables in re-engineered PHP Engine. Added PHP Data Objects (PDO) as a consistent interface for accessing databases.
5.2.0 Enabled the filter extension by default. Native JSON
JSON
JSON , or JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects...

 support.
5.2.17 Fix of critical vulnerability connected to floating point.
5.3.0 Namespace
Namespace (computer science)
A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols . An identifier defined in a namespace is associated only with that namespace. The same identifier can be independently defined in multiple namespaces...

 support; Late static bindings
Name binding
In programming languages, name binding is the association of objects with identifiers. An identifier bound to an object is said to reference that object. Machine languages have no built-in notion of identifiers, but name-object bindings as a service and notation for the programmer is implemented...

, Jump label (limited goto
Goto
goto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...

), Native closures
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...

, Native PHP archives (phar), garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

 for circular references, improved Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 support, sqlite3, mysqlnd as a replacement for libmysql as underlying library for the extensions that work with MySQL
MySQL
MySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...

, fileinfo as a replacement for mime_magic for better MIME
MIME
Multipurpose Internet Mail Extensions is an Internet standard that extends the format of email to support:* Text in character sets other than ASCII* Non-text attachments* Message bodies with multiple parts...

 support, the Internationalization extension, and deprecation of ereg extension.
5.3.1 Over 100 bug fixes, some of which were security fixes.
5.3.2 Includes a large number of bug fixes.
5.3.3 Mainly bug and security fixes; FPM
PHP-FPM
PHP-FPM is a PHP FastCGI implementation.It is bundled with the official PHP distribution since version 5.3.3.- External Links :* *...

 SAPI.
5.3.4 Mainly bug and security fixes; improvements to FPM
PHP-FPM
PHP-FPM is a PHP FastCGI implementation.It is bundled with the official PHP distribution since version 5.3.3.- External Links :* *...

 SAPI.
5.3.5 Fix of critical vulnerability connected to floating point.
5.3.6 Over 60 bug fixes that were reported in the previous version.
5.3.7 This release focuses on improving the stability of the PHP 5.3.x branch with over 90 bug fixes, some of which are security related.
5.3.8 This release fixes two issues introduced in the PHP 5.3.7 release.
5.4.0 RC2 Trait Support, Removed items: register_globals, safe_mode, allow_call_time_pass_reference, session_register, session_unregister and session_is_registered. Several improvements to existing features.
6 ?.? No date set The development of PHP 6 has been delayed because the developers have decided the current approach to handling of instance unicode is not a good one, and are considering alternate ways in the next version of PHP. The updates that were intended for PHP 6 were added to PHP 5.3.0(namespace support, Late Static Bindings, lambda functions, closures, goto) and 5.4.0(traits, closure rebinding) instead.


Beginning on June 28th, 2011, the PHP Group began following a timeline for when new versions of PHP will be released. Under this timeline, at least one release should occur every month. Every one year, a minor release should occur which can include new features. Every minor release should at least have 2 years of security and bug fixes, followed by at least 1 year of only security fixes, for a total of a 3 year release process for every minor release. No new features (unless small and self contained) will be introduced into a minor release during the 3 year release process.

Usage

PHP is a general-purpose scripting language that is especially suited to server-side
Server-side scripting
Server-side scripting is a web server technology in which a user's request is verified by running a script directly on the web server to generate dynamic web pages. It is usually used to provide interactive web sites that interface to databases or other data stores. This is different from...

 web development
Web development
Web development is a broad term for the work involved in developing a web site for the Internet or an intranet . This can include web design, web content development, client liaison, client-side/server-side scripting, web server and network security configuration, and e-commerce development...

 where PHP generally runs on a web server
Web server
Web server can refer to either the hardware or the software that helps to deliver content that can be accessed through the Internet....

. Any PHP code in a requested file is executed by the PHP runtime, usually to create dynamic web page
Dynamic web page
A dynamic web page is a kind of web page that has been prepared with fresh information , for each individual viewing. It is not static because it changes with the time , the user , the user interaction , the context A dynamic web page is a kind of web page that has been prepared with fresh...

 content or dynamic images used on web sites or elsewhere. It can also be used for command-line scripting and client-side
Client-side
Client-side refers to operations that are performed by the client in a client–server relationship in a computer network.Typically, a client is a computer application, such as a web browser, that runs on a user's local computer or workstation and connects to a server as necessary...

 GUI
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

 applications. PHP can be deployed on most web server
Web server
Web server can refer to either the hardware or the software that helps to deliver content that can be accessed through the Internet....

s, many operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s and platforms
Platform (computing)
A computing platform includes some sort of hardware architecture and a software framework , where the combination allows software, particularly application software, to run...

, and can be used with many relational database management system
Relational database management system
A relational database management system is a database management system that is based on the relational model as introduced by E. F. Codd. Most popular databases currently in use are based on the relational database model....

s (RDBMS). It is available free of charge, and the PHP Group provides the complete source code for users to build, customize and extend for their own use.

PHP acts primarily as a filter
Filter (software)
A filter is a computer program to process a data stream. Some operating systems such as Unix are rich with filter programs. Even Windows has some simple filters built into its command shell, most of which have significant enhancements relative to the similar filter commands that were available in...

, taking input from a file or stream containing text and/or PHP instructions and outputting another stream of data; most commonly the output will be HTML. Since PHP 4, the PHP parser compiles
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 input to produce bytecode
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

 for processing by the Zend Engine
Zend engine
The Zend Engine is an open source scripting engine , commonly known for the important role it plays in the web automation language PHP. It was originally developed by Andi Gutmans and Zeev Suraski while they were students at the Technion - Israel Institute of Technology. They later founded a...

, giving improved performance over its interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...

 predecessor.

Originally designed to create dynamic web pages, PHP now focuses mainly on server-side scripting
Server-side scripting
Server-side scripting is a web server technology in which a user's request is verified by running a script directly on the web server to generate dynamic web pages. It is usually used to provide interactive web sites that interface to databases or other data stores. This is different from...

, and it is similar to other server-side scripting languages that provide dynamic content from a web server to a client
Client (computing)
A client is an application or system that accesses a service made available by a server. The server is often on another computer system, in which case the client accesses the service by way of a network....

, such as Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

's ASP.NET
ASP.NET
ASP.NET is a Web application framework developed and marketed by Microsoft to allow programmers to build dynamic Web sites, Web applications and Web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages ...

, Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...

' JavaServer Pages
JavaServer Pages
JavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...

, and mod perl
Mod perl
mod_perl is an optional module for the Apache HTTP server. It embeds a Perl interpreter into the Apache server, so that dynamic content produced by Perl scripts can be served in response to incoming requests, without the significant overhead of re-launching the Perl interpreter for each request...

. PHP has also attracted the development of many frameworks
Software framework
In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by user code, thus providing application specific software...

 that provide building blocks and a design structure to promote rapid application development
Rapid application development
Rapid application development is a software development methodology that uses minimal planning in favor of rapid prototyping. The "planning" of software developed using RAD is interleaved with writing the software itself...

 (RAD). Some of these include CakePHP
CakePHP
CakePHP is an open source web application framework for producing web applications. It is written in PHP, modeled after the concepts of Ruby on Rails, and distributed under the MIT License.-History:...

, Symfony
Symfony
Symfony is a web application framework written in PHP which follows the model-view-controller paradigm. Released under the MIT license, Symfony is free software...

, CodeIgniter, and Zend Framework
Zend Framework
Zend Framework is an open source, object-oriented web application framework implemented in PHP 5 and licensed under the New BSD License.-Licensing:...

, offering features similar to other web application frameworks.

The LAMP
LAMP (software bundle)
LAMP is an acronym for a solution stack of free, open source software, referring to the first letters of Linux , Apache HTTP Server, MySQL and PHP , principal components to build a viable general purpose web server.The GNU project is advocating people to use the term "GLAMP" since what is known as...

 architecture has become popular in the web industry as a way of deploying web applications. PHP is commonly used as the P in this bundle alongside Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

, Apache
Apache HTTP Server
The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...

 and MySQL
MySQL
MySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...

, although the P may also refer to Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

 or Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

 or some combination of the three. Similar packages are also available for Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 and Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

, then called WAMP
WAMP
WAMPs are packages of independently-created programs installed on computers that use a Microsoft Windows operating system.WAMP is an acronym formed from the initials of the operating system Microsoft Windows and the principal components of the package: Apache, MySQL and one of PHP, Perl or Python....

 and MAMP
MAMP
The acronym MAMP refers to a set of free software programs commonly used together to run dynamic web sites on servers running the Apple Macintosh operating system, Mac OS X:* Mac OS X, the operating system;* Apache, the Web server;...

, with the first letter standing for the respective operating system.

As of April 2007, over 20 million Internet domains had web services hosted on servers with PHP installed and mod_php was recorded as the most popular Apache HTTP Server
Apache HTTP Server
The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...

 module.
PHP is used as the server-side programming language on 75% of all web servers. Web content management system
Web content management system
A web content management system is a software system that provides website authoring, collaboration, and administration tools designed to allow users with little knowledge of web programming languages or markup languages to create and manage website content with relative ease...

s written in PHP include MediaWiki
MediaWiki
MediaWiki is a popular free web-based wiki software application. Developed by the Wikimedia Foundation, it is used to run all of its projects, including Wikipedia, Wiktionary and Wikinews. Numerous other wikis around the world also use it to power their websites...

,
Joomla,
eZ Publish
EZ publish
-External links:* * * * * *...

,
WordPress
WordPress
WordPress is a free and open source blogging tool and publishing platform powered by PHP and MySQL. It is often customized into a content management system . It has many features including a plug-in architecture and a template system. WordPress is used by over 14.7% of Alexa Internet's "top 1...

, Drupal
Drupal
Drupal is a free and open-source content management system and content management framework written in PHP and distributed under the GNU General Public License. It is used as a back-end system for at least 1.5% of all websites worldwide ranging from personal blogs to corporate, political, and...

  and Moodle
Moodle
Moodle is a free source e-learning software platform, also known as a Course Management System, Learning Management System, or Virtual Learning Environment...

.
All websites created using these tools are written in PHP, including the user-facing portion of
Wikipedia
Wikipedia
Wikipedia is a free, web-based, collaborative, multilingual encyclopedia project supported by the non-profit Wikimedia Foundation. Its 20 million articles have been written collaboratively by volunteers around the world. Almost all of its articles can be edited by anyone with access to the site,...

, Facebook
Facebook
Facebook is a social networking service and website launched in February 2004, operated and privately owned by Facebook, Inc. , Facebook has more than 800 million active users. Users must register before using the site, after which they may create a personal profile, add other users as...

,
and Digg
Digg
Digg is a social news website. Prior to Digg v4, its cornerstone function consisted of letting people vote stories up or down, called digging and burying, respectively. Digg's popularity prompted the creation of copycat social networking sites with story submission and voting systems...

.

Security

Vulnerabilities are caused mostly by not following best practice programming rules: technical security flaws of the language itself or of its core libraries are not frequent (23 in 2008, about 1% of the total). Recognizing that programmers cannot be trusted, some languages include taint checking
Taint checking
Taint checking is a feature in some computer programming languages, such as Perl and Ruby, designed to increase security by preventing malicious users from executing commands on a host computer...

 to detect automatically the lack of input validation
Data validation
In computer science, data validation is the process of ensuring that a program operates on clean, correct and useful data. It uses routines, often called "validation rules" or "check routines", that check for correctness, meaningfulness, and security of data that are input to the system...

 which induces many issues. Such a feature is being developed for PHP, but its inclusion in a release has been rejected several times in the past.

Hosting PHP applications on a server requires careful and constant attention to
deal with these security risks. There are advanced protection patches such as Suhosin
Suhosin
Suhosin is an open source patch for PHP."The goal behind Suhosin is to be a safety net that protects servers from insecure PHP coding practices."In some Linux distributions it is shipped by default....

 and Hardening-Patch, especially designed for web hosting environments.

PHPIDS
PHPIDS
PHPIDS is an open source PHP Web Application Intrusion Detection System. It was written by Mario Heiderich, Christian Matthies, Lars H. Strojny and several others in March 2007...

 adds security to any PHP application to defend against intrusions. PHPIDS detects Cross-site scripting
Cross-site scripting
Cross-site scripting is a type of computer security vulnerability typically found in Web applications that enables attackers to inject client-side script into Web pages viewed by other users. A cross-site scripting vulnerability may be used by attackers to bypass access controls such as the same...

 (XSS), SQL injection
SQL injection
A SQL injection is often used to attack the security of a website by inputting SQL statements in a web form to get a badly designed website in order to dump the database content to the attacker. SQL injection is a code injection technique that exploits a security vulnerability in a website's software...

, header injection, Directory traversal
Directory traversal
A directory traversal consists in exploiting insufficient security validation / sanitization of user-supplied input file names, so that characters representing "traverse to parent directory" are passed through to the file APIs....

, Remote File Execution, Local File Inclusion, Denial of Service (DoS).

Syntax

PHP Test


echo 'Hello World';
/* echo("Hello World"); works as well,
although echo is not a function, but a
language construct. In some cases, such
as when multiple parameters are passed
to echo, parameters cannot be enclosed
in parentheses. */
?>




Hello world program
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

 in PHP code embedded within HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

 code


The PHP interpreter only executes PHP code within its delimiter
Delimiter
A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values.Delimiters represent...

s. Anything outside its delimiters is not processed by PHP (although non-PHP text is still subject to control structures described within PHP code). The most common delimiters are to open and ?> to close PHP sections. delimiters are also available, as are the shortened forms or (which is used to echo back a string
String (computer science)
In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....

 or variable
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

) and ?> as well as ASP
Active Server Pages
Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated Web pages. Initially released as an add-on to Internet Information Services via the Windows NT 4.0 Option Pack Active Server Pages (ASP), also known as Classic...

-style short forms <% or <%= and %>. While short delimiters are used, they make script files less portable as support for them can be disabled in the PHP configuration, and so they are discouraged. The purpose of all these delimiters is to separate PHP code from non-PHP code, including HTML.

The first form of delimiters, and ?>, in XHTML
XHTML
XHTML is a family of XML markup languages that mirror or extend versions of the widely-used Hypertext Markup Language , the language in which web pages are written....

 and other XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 documents, creates correctly formed XML 'processing instructions'. This means that the resulting mixture of PHP code and other markup in the server-side file is itself well-formed XML.

Variables are prefixed with a dollar symbol
Dollar sign
The dollar or peso sign is a symbol primarily used to indicate the various peso and dollar units of currency around the world.- Origin :...

, and a type
Primitive type
In computer science, primitive data type is either of the following:* a basic type is a data type provided by a programming language as a basic building block...

 does not need to be specified in advance. Unlike function and class names, variable names are case sensitive. Both double-quoted ("") and heredoc
Heredoc
A here document is a way of specifying a string literal in command line shells including Unix shells and in programming or scripting languages such as Perl, PHP, Python, PowerShell and Ruby...

 strings provide the ability to interpolate a variable's value into the string. PHP treats newline
Newline
In computing, a newline, also known as a line break or end-of-line marker, is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line—that is, on the next line below the...

s as whitespace
Whitespace (computer science)
In computer science, whitespace is any single character or series of characters that represents horizontal or vertical space in typography. When rendered, a whitespace character does not correspond to a visual mark, but typically does occupy an area on a page...

 in the manner of a free-form language
Free-form language
In computer programming, a free-form language is a programming language in which the positioning of characters on the page in program text is not significant. Program text does not need to be placed in specific columns as on old punched card systems, and frequently ends of lines are not significant...

 (except when inside string quotes), and statements are terminated by a semicolon. PHP has three types of comment syntax: /* */ marks block and inline comments; // as well as # are used for one-line comments. The echo statement is one of several facilities PHP provides to output text (e.g. to a web browser).

In terms of keywords and language syntax, PHP is similar to most high level languages that follow the C style syntax. if conditions, for and while loops, and function returns are similar in syntax to languages such as C, C++, Java and Perl.

Data types

PHP stores whole numbers in a platform-dependent range, either a 64-bit or 32-bit signed
Signed number representations
In computing, signed number representations are required to encode negative numbers in binary number systems.In mathematics, negative numbers in any base are represented by prefixing them with a − sign. However, in computer hardware, numbers are represented in binary only without extra...

 integer
Integer (computer science)
In computer science, an integer is a datum of integral data type, a data type which represents some finite subset of the mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values....

 equivalent to the C-language long type
C variable types and declarations
In the C programming language, data types refers to an extensive system for declaring variables of different types. The language itself provides basic arithmetic types and syntax to build array and compound types...

. Unsigned integers are converted to signed values in certain situations; this behavior is different from other programming languages. Integer variables can be assigned using decimal (positive and negative), octal
Octal
The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. Numerals can be made from binary numerals by grouping consecutive binary digits into groups of three...

, and hexadecimal
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

 notations. Floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

 numbers are also stored in a platform-specific range. They can be specified using floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

 notation, or two forms of scientific notation
Scientific notation
Scientific notation is a way of writing numbers that are too large or too small to be conveniently written in standard decimal notation. Scientific notation has a number of useful properties and is commonly used in calculators and by scientists, mathematicians, doctors, and engineers.In scientific...

. PHP has a native Boolean
Boolean datatype
In computer science, the Boolean or logical data type is a data type, having two values , intended to represent the truth values of logic and Boolean algebra...

 type that is similar to the native Boolean types in Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

. Using the Boolean type conversion rules, non-zero values are interpreted as true and zero as false, as in Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

 and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

. The null data type represents a variable that has no value. The only value in the null data type is NULL. Variables of the "resource" type represent references to resources from external sources. These are typically created by functions from a particular extension, and can only be processed by functions from the same extension; examples include file, image, and database resources. Arrays can contain elements of any type that PHP can handle, including resources, objects, and even other arrays. Order is preserved in lists of values and in hashes
Hash table
In computer science, a hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys , to their associated values . Thus, a hash table implements an associative array...

 with both keys and values, and the two can be intermingled. PHP also supports strings, which can be used with single quotes, double quotes, nowdoc or heredoc syntax
Heredoc
A here document is a way of specifying a string literal in command line shells including Unix shells and in programming or scripting languages such as Perl, PHP, Python, PowerShell and Ruby...

.

The Standard PHP Library (SPL) attempts to solve standard problems and implements efficient data access interfaces and classes.

Functions

PHP has hundreds of base functions and thousands more via extensions. These functions are well documented on the PHP site; however, the built-in library has a wide variety of naming conventions and inconsistencies. PHP currently has no functions for thread
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...

 programming, although it does support multiprocess programming on POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 systems.

Additional functions can be defined by a developer:

function myFunction { //declares a function, this is named myFunction
return 'John Doe'; //returns the value 'John Doe'
}

echo 'My name is ' . myFunction . '!'; //outputs the text and the return variable of the
//myFunction, the function is also called
//the result of the output will be 'My name is John Doe!'

PHP 5.2 and earlier

Functions are not first-class function
First-class function
In computer science, a programming language is said to have first-class functions if it treats functions as first-class objects. Specifically, this means that the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning...

s and can only be referenced by their name, directly or dynamically by a variable containing the name of the function. User-defined functions can be created at any time without being prototyped
Function prototype
A function prototype in C, Perl or C++ is a declaration of a function that omits the function body but does specify the function's return type, name, arity and argument types...

. Functions can be defined inside code blocks, permitting a run-time decision
Dynamic dispatch
In computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code at runtime. This is done to support the cases where the appropriate method can't be determined at compile-time...

 as to whether or not a function should be defined. Function calls must use parentheses, with the exception of zero argument class constructor
Constructor (computer science)
In object-oriented programming, a constructor in a class is a special type of subroutine called at the creation of an object. It prepares the new object for use, often accepting parameters which the constructor uses to set any member variables required when the object is first created...

 functions called with the PHP new operator, where parentheses are optional. PHP supports quasi-anonymous function
Anonymous function
In programming language theory, an anonymous function is a function defined, and possibly called, without being bound to an identifier. Anonymous functions are convenient to pass as an argument to a higher-order function and are ubiquitous in languages with first-class functions such as Haskell...

s through the create_function function, although they are not true anonymous functions because anonymous functions are nameless, but functions can only be referenced by name, or indirectly through a variable $function_name;, in PHP.

PHP 5.3 and newer

PHP gained support for closures
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...

. True anonymous function
Anonymous function
In programming language theory, an anonymous function is a function defined, and possibly called, without being bound to an identifier. Anonymous functions are convenient to pass as an argument to a higher-order function and are ubiquitous in languages with first-class functions such as Haskell...

s are supported using the following syntax:

function getAdder($x) {
return function($y) use ($x) {
return $x + $y;
};
}

$adder = getAdder(8);
echo $adder(2); // prints "10"

Here, the getAdder function creates a closure using the parameter $x (the keyword use imports a variable from the lexical context), which takes an additional argument $y and returns it to the caller. Such a function is a first class object, meaning that it can be stored in a variable, passed as a parameter to other functions, etc.
For more details see Lambda functions and closures RFC.

The goto
Goto
goto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...

 flow control statement is used as follows:

function lock {
$file = fopen('file.txt', 'r+');
retry:
if (!flock($file, LOCK_EX & LOCK_NB)) {
goto retry;
}
fwrite($file, 'Success!');
fclose($file);
return 0;
}

When flock is called, PHP opens a file and tries to lock it. The target label retry: defines the point to which execution should return if flock is unsuccessful and goto retry; is called. The goto statement is restricted and requires that the target label be in the same file and context.


The goto statement has been supported since PHP 5.3.

Objects

Basic object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 functionality was added in PHP 3 and improved in PHP 4. Object handling was completely rewritten for PHP 5, expanding the feature set and enhancing performance. In previous versions of PHP, objects were handled like value type
Value type
In computer science, the term value type is commonly used to refer to one of two kinds of data types: Types of values or Types of objects with deep copy semantics.- Types of Values :...

s. The drawback of this method was that the whole object was copied when a variable was assigned or passed as a parameter to a method. In the new approach, objects are referenced by handle
Handle (computing)
In computer programming, a handle is a particular kind of smart pointer. Handles are used when application software references blocks of memory or objects managed by another system, such as a database or an operating system....

, and not by value. PHP 5 introduced private and protected member variable
Member variable
In object-oriented programming, a member variable is a variable that is associated with a specific class, and accessible for all its methods. If there is only one copy of the variable shared with all instances of the class, it is called a class variable or static member variable...

s and methods, along with abstract classes
Abstract type
In programming languages, an abstract type is a type in a nominative type system which cannot be instantiated. An abstract type may have no implementation, or an incomplete implementation...

 and final classes as well as abstract methods and final methods. It also introduced a standard way of declaring constructors
Constructor (computer science)
In object-oriented programming, a constructor in a class is a special type of subroutine called at the creation of an object. It prepares the new object for use, often accepting parameters which the constructor uses to set any member variables required when the object is first created...

 and destructors
Destructor (computer science)
In object-oriented programming, a destructor is a method which is automatically invoked when the object is destroyed...

, similar to that of other object-oriented languages such as C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, and a standard exception handling
Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....

 model. Furthermore, PHP 5 added interfaces
Interface (computer science)
In the field of computer science, an interface is a tool and concept that refers to a point of interaction between components, and is applicable at the level of both hardware and software...

 and allowed for multiple interfaces to be implemented. There are special interfaces that allow objects to interact with the runtime system. Objects
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...

 implementing ArrayAccess can be used with array
Array data type
In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

 syntax and objects
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...

 implementing Iterator
Iterator
In computer programming, an iterator is an object that enables a programmer to traverse a container. Various types of iterators are often provided via a container's interface...

 or IteratorAggregate can be used with the foreach language construct
Language construct
A language construct is a syntactically allowable part of a program that may be formed from one or more lexical tokens in accordance with the rules of a programming language....

. There is no virtual table feature in the engine, so static variable
Static variable
In computer programming, a static variable is a variable that has been allocated statically — whose lifetime extends across the entire run of the program...

s are bound with a name instead of a reference at compile time.

If the developer creates a copy of an object using the reserved word clone, the Zend engine will check if a __clone method has been defined or not. If not, it will call a default __clone which will copy the object's properties. If a __clone method is defined, then it will be responsible for setting the necessary properties in the created object. For convenience, the engine will supply a function that imports the properties of the source object, so that the programmer can start with a by-value replica of the source object and only override properties that need to be changed.

Basic example of object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 as described above:

class Person {
public $firstName;
public $lastName;

public function __construct($firstName, $lastName = ) { //Optional parameter
$this->firstName = $firstName;
$this->lastName = $lastName;
}

public function greet {
return "Hello, my name is " . $this->firstName . " " . $this->lastName . ".";
}

static public function staticGreet($firstName, $lastName) {
return "Hello, my name is " . $firstName . " " . $lastName . ".";
}
}

$he = new Person('John', 'Smith');
$she = new Person('Sally', 'Davis');
$other = new Person('Joe');

echo $he->greet; // prints "Hello, my name is John Smith."
echo '
';
echo $she->greet; // prints "Hello, my name is Sally Davis."
echo '
';
echo $other->greet; // prints "Hello, my name is Joe ."
echo '
';
echo Person::staticGreet('Jane', 'Doe'); // prints "Hello, my name is Jane Doe."

Visibility of properties and methods

The visibility of PHP properties and methods refers to visibility in PHP. It is defined using the keyword
Keyword (computer programming)
In computer programming, a keyword is a word or identifier that has a particular meaning to the programming language. The meaning of keywords — and, indeed, the meaning of the notion of keyword — differs widely from language to language....

s public, private, and protected. The default is public, if only var
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

 is used; var is a synonym for public. Items declared public can be accessed everywhere. protected limits access to inherited classes (and to the class that defines the item). private limits visibility only to the class that defines the item. Objects of the same type have access to each other's private and protected members even though they are not the same instance. PHP's member visibility features have sometimes been described as "highly useful." However, they have also sometimes been described as "at best irrelevant and at worst positively harmful."

Speed optimization

PHP source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

 is compiled
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 on-the-fly to an internal format that can be executed by the PHP engine. In order to speed up execution time and not have to compile the PHP source code every time the webpage is accessed, PHP scripts can also be deployed in executable format using a PHP compiler.

Code optimizers aim to enhance the performance of the compiled code by reducing its size, merging redundant instructions and making other changes that can reduce the execution time. With PHP, there are often opportunities for code optimization
Optimization (computer science)
In computer science, program optimization or software optimization is the process of modifying a software system to make some aspect of it work more efficiently or use fewer resources...

. An example of a code optimizer is the eAccelerator
EAccelerator
eAccelerator is a PHP accelerator derived from the MMCache extension for the PHP programming language. eAccelerator provides a bytecode cache. eAccelerator is open source and thereby free to use and distribute. Old and unmaintained versions also provided an encoder.Every time a PHP script is...

 PHP extension.

Another approach for reducing compilation overhead for PHP servers is using an opcode cache
PHP accelerator
A PHP accelerator is a PHP extension designed to improve the performance of software applications written in the PHP programming language.- Operation :...

. Opcode caches work by caching
Cache
In computer engineering, a cache is a component that transparently stores data so that future requests for that data can be served faster. The data that is stored within a cache might be values that have been computed earlier or duplicates of original values that are stored elsewhere...

 the compiled form of a PHP script (opcode
Opcode
In computer science engineering, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question...

s) in shared memory
Shared memory
In computing, shared memory is memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them or avoid redundant copies. Depending on context, programs may run on a single processor or on multiple separate processors...

 to avoid the overhead of parsing
Parsing
In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a text, made of a sequence of tokens , to determine its grammatical structure with respect to a given formal grammar...

 and compiling the code every time the script runs. An opcode cache, APC, will be built into an upcoming release of PHP.

Opcode caching and code optimization can be combined for best efficiency, as the modifications do not depend on each other (they happen in distinct stages of the compilation).

Compilers

The PHP language was originally implemented as an interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...

. Several compilers have been developed which decouple the PHP language from the interpreter. Advantages of compilation include better execution speed, static analysis, and improved interoperability with code written in other languages. PHP compilers of note include Phalanger
Phalanger (compiler)
Phalanger is a project which was started at Charles University in Prague and was supported by Microsoft. It compiles source code written in the PHP scripting language into CIL byte-code. It handles the beginning of a compiling process which is completed by the JIT compiler component of the .NET...

, which compiles PHP into CIL
Common Intermediate Language
Common Intermediate Language is the lowest-level human-readable programming language defined by the Common Language Infrastructure specification and is used by the .NET Framework and Mono...

 byte-code, and HipHop
HipHop for PHP
HipHop for PHP is a source code transformer for PHP script code. HipHop programmatically transforms PHP source code into highly optimized C++ and then uses g++ to compile it to machine code...

, developed at Facebook and now available as open source, which transforms the PHP Script into C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, then compiles it, reducing server load up to 50%.

Resources

PHP includes free and open source libraries with the core build. PHP is a fundamentally Internet
Internet
The Internet is a global system of interconnected computer networks that use the standard Internet protocol suite to serve billions of users worldwide...

-aware system with modules built in for accessing FTP
File Transfer Protocol
File Transfer Protocol is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as the Internet. FTP is built on a client-server architecture and utilizes separate control and data connections between the client and server...

 servers, many database servers, embedded SQL libraries such as embedded PostgreSQL
PostgreSQL
PostgreSQL, often simply Postgres, is an object-relational database management system available for many platforms including Linux, FreeBSD, Solaris, MS Windows and Mac OS X. It is released under the PostgreSQL License, which is an MIT-style license, and is thus free and open source software...

, MySQL
MySQL
MySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...

 and SQLite
SQLite
SQLite is an ACID-compliant embedded relational database management system contained in a relatively small C programming library. The source code for SQLite is in the public domain and implements most of the SQL standard...

, LDAP
Lightweight Directory Access Protocol
The Lightweight Directory Access Protocol is an application protocol for accessing and maintaining distributed directory information services over an Internet Protocol network...

 servers, and others. Many functions familiar to C programmers such as those in the stdio family are available in the standard PHP build.

PHP allows developers to write extensions
Extension (computing)
Software extension, is a file containing programming that serves to extend the capabilities of or data available to a more basic program. It is a kind of list of commands which are directly included in the program. This term often coincides with the plug-in...

 in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 to add functionality to the PHP language. These can then be compiled into PHP or loaded dynamically at runtime. Extensions have been written to add support for the Windows API
Windows API
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name "Windows API" more accurately reflects its roots in 16-bit Windows and its support on...

, process management on Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s, multibyte strings (Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

), cURL
CURL
cURL is a computer software project providing a library and command-line tool for transferring data using various protocols. The cURL project produces two products, libcurl and cURL...

, and several popular compression formats
Archive format
An archive format is the file format of an archive file. The archive format is determined by the file archiver. Some archive formats are well-defined by their authors and have become conventions supported by multiple vendors and/or open-source communities....

. Some more unusual features include integration with Internet Relay Chat
Internet Relay Chat
Internet Relay Chat is a protocol for real-time Internet text messaging or synchronous conferencing. It is mainly designed for group communication in discussion forums, called channels, but also allows one-to-one communication via private message as well as chat and data transfer, including file...

, dynamic generation of images and Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform used to add animation, video, and interactivity to web pages. Flash is frequently used for advertisements, games and flash animations for broadcast...

 content, and even speech synthesis
Speech synthesis
Speech synthesis is the artificial production of human speech. A computer system used for this purpose is called a speech synthesizer, and can be implemented in software or hardware...

. The PHP Extension Community Library (PECL) project is a repository for extensions to the PHP language.

Zend
Zend Technologies
Zend Technologies Ltd. is an Israeli world wide web infrastructure software company with headquarters in Cupertino, California, U.S., technology center in Ramat Gan, Tel Aviv, Israel and offices in France, Italy and Germany...

 provides a certification
Zend Certified Engineer
The Zend Certified Engineer certification is an internationally-recognized PHP certification established by Zend Technologies. An exam must be passed in order to be awarded the certification. It is intended to prove that a person is fully qualified to develop PHP web applications...

 exam for programmers to become certified PHP developers.

See also

  • Comparison of programming languages
    Comparison of programming languages
    Programming languages are used for controlling the behavior of a machine . Like natural languages, programming languages conform to rules for syntax and semantics.There are thousands of programming languages and new ones are created every year...

  • Comparison of PHP Frameworks
  • List of AMP packages
  • List of PHP editors
  • PHP accelerator
    PHP accelerator
    A PHP accelerator is a PHP extension designed to improve the performance of software applications written in the PHP programming language.- Operation :...

  • PHP-FPM
    PHP-FPM
    PHP-FPM is a PHP FastCGI implementation.It is bundled with the official PHP distribution since version 5.3.3.- External Links :* *...

  • PHP-GTK
    PHP-GTK
    PHP-GTK is a set of language bindings for PHP which allow GTK+ GUI applications to be written in PHP. PHP-GTK provides an object-oriented interface to GTK+ classes and functions.- History:...

  • Template processor
    Template processor
    A template processor is software or a software component that is designed to combine one or moretemplates with a data model to produceone or more result documents...

  • EasyPHP
    EasyPHP
    EasyPHP is a software bundle for Windows enabling PHP and MySQL development on a developer's personal computer.Launched in 1999, EasyPHP was the first WAMP software bundle available. EasyPHP installs web server services onto the Windows computer and allows quick-and-easy development of PHP and...

  • XAMPP
    XAMPP
    XAMPP is a free and open source cross-platform web server solution stack package, consisting mainly of the Apache HTTP Server, MySQL database, and interpreters for scripts written in the PHP and Perl programming languages.-Etymology:...

  • Zend Certified Engineer
    Zend Certified Engineer
    The Zend Certified Engineer certification is an internationally-recognized PHP certification established by Zend Technologies. An exam must be passed in order to be awarded the certification. It is intended to prove that a person is fully qualified to develop PHP web applications...

  • Zend Server
    Zend Server
    Zend Server refers to a PHP application server product line offered by Zend Technologies, released in early 2009 with production support available for Windows and Linux. It is available in two versions, Zend Server and Zend Server Community Edition. Zend Server is supported on x86 and x86-64...

    Community Edition

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK