Sunday, March 15, 2015

PHP: Lower the Entry Process for your website

If you have a website that is using PHP on the server side, you may be struggling with the Entry Process reaching the top limit of your web host.

What is an Entry Process?  Basically, it means that a process is launched on your web server host each time a page is requested.  If you have a lot of traffic, this means that at some point, you may reach the Entry Process Limits imposed by your web host and your visitor will get a message that too many resources are being used.

This is really annoying but there is not much that you can do about it if you are hosting static html page.  On the other hand, this issue can be triggered by your dynamic web pages and can be improved by tweaking the rendered code to be faster.


If you are using PHP, as a lot of web developers are doing, you may have a webpage that does look like this:
<?php $title = "Crombz.com - The best website!";?>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
   Hello, this is my webpage and the title is <?php echo $title; ?>
</body>
</html>
This is a regular case where you will embed in the HTML code some part of PHP code.  It does work nicely but has a major drawback:  The page will be rendered a bit slower than a pure HTML page.

Since a PHP webpage takes a bit more time to be served by your host, you do increase the chance of  reaching the Entry Process Limits if you have a lot of traffic.  Assuming that you are limited to 10 Entry Processes at the same time, if the time to render your PHP page takes 0.2 seconds, you will have a maximum of 5 visitors being able to view your page at the same time.

I have struggled this week with this issue on my website Crombz.com.   After reviewing the code, I realized that PHP had to parse a mix of HTML and PHP to be able to render the page properly.  After some experimenting and tweaking, I modified my code like this:

<?php
    $title = "Crombz.com - The best website!";
?>

<html>
<head>

<?php
    echo '<title>'.$title.'</title>';
?>

</head>
<body>

<?php
   echo 'Hello, this is my webpage and the title is .$title;
?>

</body>
</html>
I made sure that a single line was either a pure HTML code or a pure PHP code...  It has lowered the rendering time so much that even with 30 visitors, I am not reaching the Entry Process Limit of my web host.

Of course, your code will be a bit more complex but the benefits are that you will lower the chance of reaching the Entry Process Limits even with a high traffic.

I haven't tested rendering a webpage in pure PHP, but it would probably be faster than having mixed lines of HTML and PHP.

Happy coding!