Friday, 14 August 2015

Advantages of PHP

If you ask a group of PHP programmers why they use PHP, you will hear a range of answers"it's fast," "it's easy to use," and more. This section briefly summarizes the main reasons for using PHP as opposed to a competing language.


1. The HTML Relationship

  • When used to output text, PHP is embedded inside the text in code islands, in contrast to languages like Perl, where text is embedded inside the Perl script. The most common way to open and close PHP code blocks is by <?php and ?>. Here is an example of a simple page, shown in Perl first and then in PHPdon't worry about what the code means for now:
 #!/usr/bin/perl
    print <<"EOHTML"
    <html>
    <body>
    <p>Welcome, $Name</p>
    </body>
    </html>
    EOHTML

And now in PHP:
    <html>
    <body>
    <p>Welcome, <?php print $Name; ?></p>
    </body>
    </html>


The PHP version is only three lines shorter but easier to read, because it 
doesn't have the extra complexity around it.Some modules for Perl (particularly CGI.pm) help, 
but PHP continues to have a lead in terms of readability.
If you wanted to, you could write your PHP script like the Perl script: switch 
to PHP mode and print everything out from there.


Apart from legibility, another advantage to having most of the page in HTML is 
that it makes it possible to use integrated development environments (IDEs), 
whereas products like Dreamweaver and FrontPage muddle up Perl's print 
statements.

2. Interpreting Versus Compiling

Behind the scenes, PHP compiles your script down to a series of instructions (called opcodes), and these instructions are then executed one by one until the script terminates. This is different from conventional compiled languages such as C++ (but unlike Java), which compile the code into an executable run time and then run that executable whenever the code is encountered again. This constant recompilation may seem a waste of processor time, but it helps because you no longer need worry about recompiling your scripts when you make any changes. On the flip side, many scripts take longer to compile than they do to execute; fortunately, that is nullified by the use of PHP code caches.


One major advantage to having interpreted code is that all memory used by the script is managed by PHP, and the Zend Engine automatically cleans up allocated memory after every script has finished. This means that you do not need to worry about closing database links, freeing memory assigned to images, and so on, because PHP will do it for you. That isn't to say you should be lazy and make PHP do all the workthere are functions available for you to specifically clean up your memory, and you should use them if you have very tight memory requirements.


3. Output Control

In general use, PHP is embedded inside HTML in code islands that start with <?php and end with ?>, but you can reverse this by writing your whole script as one big PHP code island and printing HTML as necessary. Going back to the example shown previously, PHP code can look almost identical to the Perl code by printing the HTML from inside our PHP code:

<?php
            print "<html>\n";
            print "<body>\n";
            print "<p>Welcome, $Name</p>\n";
            print "</body>\n";
            print "</html>\n";
?>

The print( ) function outputs the text enclosed in quotation marks to the client. "\n" means "start new line in the output " and it serves as a "pretty printer"something that makes the output look more attractive.
PHP also has powerful output buffering that further increases your control over the output flow. An output buffer can be thought of as a place where you can queue up content for outputting. Once you start a buffer, any output is automatically put into that buffer and not seen unless the buffer is closed and flushed.
The advantage to this output buffering is twofold. First, it allows you to clean the buffer if you decide that the content it holds is no longer needed. When a buffer is cleaned, all its stored output is deleted as if it were never there, and the output for that buffer is started from scratch.
Second, output buffering allows you to break the traditional ordering of web pagesthat of headers first and content later. Owing to the fact that you queue up all your output, you can send content first, then headers, then more content, then finally flush the buffer. PHP internally rearranges the buffer so that headers come before content.
4. Performance
PHP is one of the fastest scripting languages around, rivalling both Perl and ASP. However, the developers continue to target performance as a
key area for improvement, many areas have seen significant optimization.
When combined with a code cache, PHP's performance usually at least doubles, although many scripts show much larger increases.






PHP instalition


  • Even if you intend to use a remote web server for your site, where PHP is already installed, it is still beneficial to be able to install PHP on your own machine so that you can test your pages more easily.

  • Installing PHP yourself opens up many possibilities: you get to choose exactly which extensions are available, which options are enabled, and the filesystem layout that you want. Of course, if you intend to upload your scripts to a different server at the end of the process, you should be careful to mimic the remote configuration on your local machine.



PHP Syntax

<?php
// PHP code goes here
?>

1. A PHP script can be placed anywhere in the document.

2. The default file extension for PHP files you save with ".php".

3. A PHP file normally contains HTML tags, and some PHP scripting code.

4. Web page that may contain PHP (Hypertext Preprocessor) code; may include PHP functions that can process online forms, get the date and time, or access information from a database, such as a MySQL database.

5. The PHP code within the Web page is processed (parsed) by a PHP engine on the Web server, which dynamically generates HTML. The HTML, which contains the Web page content, is then sent to the user's Web browser. Therefore, the user never sees the actual PHP code contained in the Web page, even when viewing the page source.

What is PHP


  • PHP is one type of serever side scripting scripting language. used for web application and website development.

  • Rasmus Lerdorf is founder of PHP

  • Which is use for build dynamic web application/Website/Blog also.

  • PHP is totally open source and very light weight SCRIPTING language rather then other scripting language this is the main reason for PHP is most populer. 

  • Current scenario worlds more then 80 % website are build using PHP.

  • When you are think to build your own business website PHP is best for you because it's totally open source.



PHP hasn't always been around, so what came before it? More importantly, why was PHP created in the first place? In this chapter, we'll look at the history behind PHP, where it has advantages over other programming languages, and where you can get help to further your PHP programming career.