T
Tiger
Guest
السلام عليكم ورحمة الله وبركاته
Advantages of PHP
I could cop out here and say that the advantages of PHP are too many to list in such a small book as this, but it seems that some people need convincing of PHP's inherent greatness, and I am very happy to oblige.
If you are not new to PHP, I still recommend you at least glance over the contents of this chapter. I find that programming in PHP is very often like playing my guitar. I can be sitting in my study strumming idly on my 12-string like I've done thousands of times before, only this time I play a different chord sequence, or strum the strings in a different manner than normal, and I think "Hey, that's cool... how come I never found that before?"
At various points in my PHP programming past, I have stumbled across functions or functionality in pretty much the same way, and responded with pretty much the same response! If you're the same, then definitely read on - it doesn't hurt to see what's on offer.
2.2.1 The HTML relationship
When used to output HTML content, PHP is embedded inside HTML in code islands, as opposed to in Perl, where HTML code 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 then in PHP - don't worry about what the code means for now:
#!/usr/bin/perl
print "<HTML> ";
print "<BODY> ";
print "<P>Welcome, </P> ";
print "</BODY> ";
print "</HTML> ";
And now in PHP:
<HTML>
<BODY>
<P>Welcome, <?php print ; ?></P>
</BODY>
</HTML>
As you can see, the PHP version is only a line shorter, but infinitely much easier to read because the majority of the page is just HTML. Some modules for Perl (particularly CGI.pm) help, but PHP continues to have a big lead in terms of readability. If you really wanted to, you could write your PHP script like the Perl script: switch to PHP mode and print everything out from there. However, it tends to get messy - as you can see!
Apart from editing legibility, another advantage to having most of the page in straight HTML is that it makes editing with commercial IDEs possible, whereas products like Dreamweaver and FrontPage trash Perl's print statements.
One key advantage to using PHP as opposed to some other solutions is that PHP code is all executed at the server, with the client only receiving the results of the script. What this means is that users never see your PHP source code because they are never sent it - they only see what you want them to see.
2.2.2 Interpreting vs. Compiling
PHP uses a blend of interpretation and compilation in order to provide the best mix of performance and flexibility to programmers.
Behind the scenes, PHP compiles your script down to a series of instructions (called opcodes) whenever it is accessed. These instructions are then executed one by one until the script terminates. This is different from conventional compiled languages such as C++ where the code is compiled down to native executable code then that executable is run from then on. Instead, PHP re-compiles your script each time it is requested.
This constant recompilation may seem a waste of processor time, but it is actually not all that bad because you no longer need to worry about hand recompiling your scripts when you make any changes. On the flip side, many scripts take longer to compile than they do to execute!
Furthermore, it provides very quick feedback during development. If you have an error somewhere in your file, PHP will refuse to compile the page until you have fixed the problem, and you are able to step through execution of your code line by line until you find the problem.
The speed hit of regular compilation is nullified entirely by the use of PHP accelerators.
One major advantage to having interpreted code is that all memory used by the script is managed by PHP, and the language automatically cleans up 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 is not to say you should be lazy and make PHP do all the work - good programmers clean up themselves, and let PHP work as backup in case something is missed.
تفضل الكتاب من هنا
حياكم الله

Advantages of PHP
I could cop out here and say that the advantages of PHP are too many to list in such a small book as this, but it seems that some people need convincing of PHP's inherent greatness, and I am very happy to oblige.
If you are not new to PHP, I still recommend you at least glance over the contents of this chapter. I find that programming in PHP is very often like playing my guitar. I can be sitting in my study strumming idly on my 12-string like I've done thousands of times before, only this time I play a different chord sequence, or strum the strings in a different manner than normal, and I think "Hey, that's cool... how come I never found that before?"
At various points in my PHP programming past, I have stumbled across functions or functionality in pretty much the same way, and responded with pretty much the same response! If you're the same, then definitely read on - it doesn't hurt to see what's on offer.
2.2.1 The HTML relationship
When used to output HTML content, PHP is embedded inside HTML in code islands, as opposed to in Perl, where HTML code 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 then in PHP - don't worry about what the code means for now:
#!/usr/bin/perl
print "<HTML> ";
print "<BODY> ";
print "<P>Welcome, </P> ";
print "</BODY> ";
print "</HTML> ";
And now in PHP:
<HTML>
<BODY>
<P>Welcome, <?php print ; ?></P>
</BODY>
</HTML>
As you can see, the PHP version is only a line shorter, but infinitely much easier to read because the majority of the page is just HTML. Some modules for Perl (particularly CGI.pm) help, but PHP continues to have a big lead in terms of readability. If you really wanted to, you could write your PHP script like the Perl script: switch to PHP mode and print everything out from there. However, it tends to get messy - as you can see!
Apart from editing legibility, another advantage to having most of the page in straight HTML is that it makes editing with commercial IDEs possible, whereas products like Dreamweaver and FrontPage trash Perl's print statements.
One key advantage to using PHP as opposed to some other solutions is that PHP code is all executed at the server, with the client only receiving the results of the script. What this means is that users never see your PHP source code because they are never sent it - they only see what you want them to see.
2.2.2 Interpreting vs. Compiling
PHP uses a blend of interpretation and compilation in order to provide the best mix of performance and flexibility to programmers.
Behind the scenes, PHP compiles your script down to a series of instructions (called opcodes) whenever it is accessed. These instructions are then executed one by one until the script terminates. This is different from conventional compiled languages such as C++ where the code is compiled down to native executable code then that executable is run from then on. Instead, PHP re-compiles your script each time it is requested.
This constant recompilation may seem a waste of processor time, but it is actually not all that bad because you no longer need to worry about hand recompiling your scripts when you make any changes. On the flip side, many scripts take longer to compile than they do to execute!
Furthermore, it provides very quick feedback during development. If you have an error somewhere in your file, PHP will refuse to compile the page until you have fixed the problem, and you are able to step through execution of your code line by line until you find the problem.
The speed hit of regular compilation is nullified entirely by the use of PHP accelerators.
One major advantage to having interpreted code is that all memory used by the script is managed by PHP, and the language automatically cleans up 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 is not to say you should be lazy and make PHP do all the work - good programmers clean up themselves, and let PHP work as backup in case something is missed.
تفضل الكتاب من هنا
حياكم الله