How to Make a PHP Script Run Faster

By adding a few lines of code to the top of your PHP script or the global PHP initialization file, you can drastically improve the load time, causing the FiverrScript Modules to run much faster. In some cases, you can improve the load time of a Web page by up to 500 percent by compressing the PHP output before it reaches the browser.


1. Then scroll down to the "Download" section in the middle of the page and click the "PHP Speedy Download" link. The file downloads and saves immediately to your hard drive.


2. Unzip the downloaded file to the directory with your other PHP files. It is important that the required PHP Speedy files be placed in the same directory as the PHP file to which you want to add the functionality.


3. Launch a text or HTML editor on your computer. Open the PHP file you wish to make run faster.


4. Go to the top of the PHP document, then find the "<php" tag and insert the following two lines of code:

require_once('class compressor php');

$compressor = new compressor('css javascript page');


5. Go to the last line of the PHP document and insert this single line of code:



6. Save the PHP document, then run the file to see it load faster.

ZLib Compression


7. Open the global "PHP ini" file from your website's server in a text editor. You may need to download the file to your local computer first, then later upload it after making the following changes.


8. Go to the "PHP" section and change the following line of code to read the same as below:

zlib output_compression = On


9. Save the "PHP ini" file in your text editor. If editing on your computer, then upload it back to the website's server.

PHP OB_GZHandler


10. Launch your text editor and open the PHP to which you wish to add compression.


11. Insert this single line of code at the very top of the PHP document after the "< php" tag:

if (substr_count($_SERVER'HTTP_ACCEPT_ENCODING', 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>


12. Save the file on your computer and run it to test the compression of your PHP, which should speed up the page's load time.


Related Post: How to Make a PHP Script Run Faster

Write a comment

Comments: 0