PHP Programming Language - Cultural View

PHP Programming Language - Cultural View PHP Programming Language - Cultural View

culturalview.com
from culturalview.com More from this publisher
10.02.2013 Views

PHP 200 Basic example of object-oriented programming as described above: Class Person { } public $first; public $last; public function construct($f,$l) { } $this->first = $f; $this->last = $l; public function greeting() { } return "Hello, my name is {$this->first} {$this->last}."; public function staticGreeting($first, $last) { } return "Hello, my name is $first $last."; $him = new Person('John','Smith'); $her = new Person('Sally','Davis'); echo $him->greeting(); // prints "Hello, my name is John Smith." echo ''; echo $her->greeting(); // prints "Hello, my name is Sally Davis." echo ''; echo Person::staticGreeting('John','Smith'); // prints "Hello, my name is John Smith."

PHP 201 Speed optimization PHP source code is compiled on-the-fly to an internal format that can be executed by the PHP engine. [68] [69] 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 reduce the runtime of the compiled code by reducing its size and making other changes that can reduce the execution time with the goal of improving performance. The nature of the PHP compiler is such that there are often opportunities for code optimization, [70] and an example of a code optimizer is the eAccelerator PHP extension. [71] Another approach for reducing overhead for high load PHP servers is using an opcode cache. Opcode caches work by caching the compiled form of a PHP script (opcodes) in shared memory to avoid the overhead of parsing and compiling the code every time the script runs. An opcode cache, APC, will be built into an upcoming release of PHP. [72] Opcode caching is also available in Zend Server Community Edition. Compilers The PHP language was originally implemented using a PHP interpreter. Several compilers now exist, which decouple the PHP language from the interpreter: • phc [73] - a C++ based compiler for PHP, using the Zend run-time for maximum compatibility • Roadsend - achieves native compilation by compiling to bigloo scheme, which in turn is compiled to C, then to machine code • Raven [74] - a rewrite of Roadsend PHP (rphp), based on LLVM and a new C++ runtime • Phalanger - compiles source code written in the PHP scripting language into CIL byte-code • Caucho Resin/Quercus [75] - compiles PHP to Java bytecode • HipHop - developed at Facebook and now available as open source, transforms the PHP Script into C++, then compiles it. • php-to-scala [76] - converts PHP to human-readable Scala source code, which the developer can compile to Java bytecode Advantages of compilation include not only better execution speed, but also obfuscation, static analysis, and improved interoperability with code written in other languages. [77] Resources PHP includes free and open source libraries with the core build. PHP is a fundamentally Internet-aware system with modules built in for accessing FTP servers, many database servers, embedded SQL libraries such as embedded PostgreSQL, MySQL and SQLite, LDAP servers, and others. Many functions familiar to C programmers such as those in the stdio family are available in the standard PHP build. [78] PHP allows developers to write extensions in C 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, process management on Unix-like operating systems, multibyte strings (Unicode), cURL, and several popular compression formats. Some more unusual features include integration with Internet Relay Chat, dynamic generation of images and Adobe Flash content, and even speech synthesis. The PHP Extension Community Library (PECL) project is a repository for extensions to the PHP language. [79] Zend provides a certification exam for programmers to become certified PHP developers.

<strong>PHP</strong> 201<br />

Speed optimization<br />

<strong>PHP</strong> source code is compiled on-the-fly to an internal format that can be executed by the <strong>PHP</strong> engine. [68] [69] In<br />

order to speed up execution time and not have to compile the <strong>PHP</strong> source code every time the webpage is accessed,<br />

<strong>PHP</strong> scripts can also be deployed in executable format using a <strong>PHP</strong> compiler.<br />

Code optimizers aim to reduce the runtime of the compiled code by reducing its size and making other changes that<br />

can reduce the execution time with the goal of improving performance. The nature of the <strong>PHP</strong> compiler is such that<br />

there are often opportunities for code optimization, [70] and an example of a code optimizer is the eAccelerator <strong>PHP</strong><br />

extension. [71]<br />

Another approach for reducing overhead for high load <strong>PHP</strong> servers is using an opcode cache. Opcode caches work<br />

by caching the compiled form of a <strong>PHP</strong> script (opcodes) in shared memory to avoid the overhead of parsing and<br />

compiling the code every time the script runs. An opcode cache, APC, will be built into an upcoming release of<br />

<strong>PHP</strong>. [72] Opcode caching is also available in Zend Server Community Edition.<br />

Compilers<br />

The <strong>PHP</strong> language was originally implemented using a <strong>PHP</strong> interpreter. Several compilers now exist, which<br />

decouple the <strong>PHP</strong> language from the interpreter:<br />

• phc [73] - a C++ based compiler for <strong>PHP</strong>, using the Zend run-time for maximum compatibility<br />

• Roadsend - achieves native compilation by compiling to bigloo scheme, which in turn is compiled to C, then to<br />

machine code<br />

• Raven [74] - a rewrite of Roadsend <strong>PHP</strong> (rphp), based on LLVM and a new C++ runtime<br />

• Phalanger - compiles source code written in the <strong>PHP</strong> scripting language into CIL byte-code<br />

• Caucho Resin/Quercus [75] - compiles <strong>PHP</strong> to Java bytecode<br />

• HipHop - developed at Facebook and now available as open source, transforms the <strong>PHP</strong> Script into C++, then<br />

compiles it.<br />

• php-to-scala [76] - converts <strong>PHP</strong> to human-readable Scala source code, which the developer can compile to Java<br />

bytecode<br />

Advantages of compilation include not only better execution speed, but also obfuscation, static analysis, and<br />

improved interoperability with code written in other languages. [77]<br />

Resources<br />

<strong>PHP</strong> includes free and open source libraries with the core build. <strong>PHP</strong> is a fundamentally Internet-aware system with<br />

modules built in for accessing FTP servers, many database servers, embedded SQL libraries such as embedded<br />

PostgreSQL, MySQL and SQLite, LDAP servers, and others. Many functions familiar to C programmers such as<br />

those in the stdio family are available in the standard <strong>PHP</strong> build. [78]<br />

<strong>PHP</strong> allows developers to write extensions in C to add functionality to the <strong>PHP</strong> language. These can then be<br />

compiled into <strong>PHP</strong> or loaded dynamically at runtime. Extensions have been written to add support for the Windows<br />

API, process management on Unix-like operating systems, multibyte strings (Unicode), cURL, and several popular<br />

compression formats. Some more unusual features include integration with Internet Relay Chat, dynamic generation<br />

of images and Adobe Flash content, and even speech synthesis. The <strong>PHP</strong> Extension Community Library (PECL)<br />

project is a repository for extensions to the <strong>PHP</strong> language. [79]<br />

Zend provides a certification exam for programmers to become certified <strong>PHP</strong> developers.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!