Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

How to increase performance of PHP!

How to increase performance of PHP!
Introduction
PHP is a language that compiles the scripts each time a user visits your website. Sometimes, it is a waste to recompile the same exact script. In this tutorial, I will introduce you to caching and other big performance tips.

Caching (Click to View)

Minification (Click to View)

Compiling JS (Click to View)

Tips (Click to View)

I hope that you guys found this helpful. I will be adding some other stuff a little later, and if anyone knows any tips that should be on here, just reply to the thread. Thanks!

Thanks for the tutorial!

but..
(Dec 17, 2013 12:25 PM)VladHQ Wrote:  
PHP Code

<?php
// http://www.theukwebdesigncompany.com/articles/php-caching.php

$cachefile = './cache/' . $_SERVER['REMOTE_ADDR'] . '.html';
$minutes = '10';
$cachetime = $minutes * 60;

if(
file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)))  { // Check if the file exists
    
include($cachefile); // if the file is cached, include it
    
die();
}
ob_start(); // Make sure to include this

/* Your script goes here */
echo 'Google:<br/>';
echo 
file_get_contents('http://www.google.com/');
echo 
'<br/>';

echo 
'Yahoo:<br/>';
echo 
file_get_contents('http://www.yahoo.com/');
echo 
'<br/>';

echo 
'Facebook:<br/>';
echo 
file_get_contents('http://www.facebook.com/');
echo 
'<br/>';

ob_start();
file_put_contents($cachefile, ob_get_contents()); // Write to cache
ob_end_flush(); 
?>
[/spoiler]
why does it do ob_start(); two times? Is it required or wans't you meant to do it?

-DJS
This is a great tutorial! I don't entirely agree with Minification as it makes it hard for other people to read it. But for those who'd like to it's also great!

I've made this a book mark as a reference just in case I need it 😁

BinKill-Ethical 🤝
Caching: Use APC
"Minification": Use GZip. GZip > minification
Compiling JS: This is not actually compilation of JS it seems, rather "minification" as you so eloquently put it. GZip would cover this if you install it correctly.
(Dec 17, 2013 12:30 PM)DJSanderrr Wrote:  Thanks for the tutorial!

but..
why does it do ob_start(); two times? Is it required or wans't you meant to do it?

-DJS

I did it on accident. I just fixed it. Thank you.

(Dec 17, 2013 12:33 PM)badbrains Wrote:  Caching: Use APC
"Minification": Use GZip. GZip > minification
Compiling JS: This is not actually compilation of JS it seems, rather "minification" as you so eloquently put it. GZip would cover this if you install it correctly.

You can't install APC on shared hosting. Most people use shared hosting right now. You could use both to save space (that's what I do).

(Dec 17, 2013 12:31 PM)t0rch Wrote:  This is a great tutorial! I don't entirely agree with Minification as it makes it hard for other people to read it. But for those who'd like to it's also great!

I've made this a book mark as a reference just in case I need it 😁

BinKill-Ethical 🤝

Thanks for the awesome feedback. If you want people to view your code, just provide a link to the actual unminified full page.

I will be adding a Cloudflare setup guide, as it does make your page load faster.
(Dec 17, 2013 01:18 PM)VladHQ Wrote:  I did it on accident. I just fixed it. Thank you.


You can't install APC on shared hosting. Most people use shared hosting right now. You could use both to save space (that's what I do).

If you're doing any serious project (that requires caching and compression) on shared hosting, you have a problem. Just my two cents.
(Dec 17, 2013 01:20 PM)badbrains Wrote:  If you're doing any serious project (that requires caching and compression) on shared hosting, you have a problem. Just my two cents.

Well I am creating a search engine right now. I have developed it for a little less than a year, and I find it better to use shared hosting as it is maintained, and I use my laptop to host the crawler in Python. It's not that bad.
I would live to hear some more feedback on this tutorial!
(Dec 20, 2013 08:22 PM)VladHQ Wrote:  I would live to hear some more feedback on this tutorial!

(Dec 17, 2013 12:33 PM)badbrains Wrote:  Caching: Use APC
"Minification": Use GZip. GZip > minification
Compiling JS: This is not actually compilation of JS it seems, rather "minification" as you so eloquently put it. GZip would cover this if you install it correctly.

^that...

You shouldn't have to cache, minify or all of that on a project you're hosting on a shared host, as Wolf said.
(Dec 21, 2013 02:15 AM)Mafugsa Bob Wrote:  ^that...

You shouldn't have to cache, minify or all of that on a project you're hosting on a shared host, as Wolf said.

But this is not just for shared hosting. If you combine this with GZIP and a cache plugin, it only benefits you.
nice info man . already bookmark :)
(Dec 17, 2013 12:25 PM)VladHQ Wrote:  [*]Use PDO or mysqli_* instead of mysql_*

I know it's better to use PDO or mysqli these days but in the performance way it doesn't really matter.

http://www.php.net/manual/en/mysqlinfo.api.choosing.php Wrote:It is recommended to use either the mysqli or PDO_MySQL extensions. It is not recommended to use the old mysql extension for new development, as it has been deprecated as of PHP 5.5.0 and will be removed in the future. A detailed feature comparison matrix is provided below. The overall performance of all three extensions is considered to be about the same. Although the performance of the extension contributes only a fraction of the total run time of a PHP web request. Often, the impact is as low as 0.1%.

Further it's a nice tutorial
Thanks for the feedback, guys, I really appreciate it.
Hate to see this thread go dead, I worked on this for a couple hours.
Cache assets and static files with Nginx and Varnish on frontend with Apache on backend. Optimise Apache configuration. Run an OPCode cacher (or maybe HipHop?). Run a data-store cacher.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by ZaffriApr 2, 2016 05:25 AM 2 116 Apr 2, 2016 05:25 AM
Last Post: Zaffri
[PHP] by spider.netMay 3, 2011 06:22 AM 14 336 May 3, 2011 06:22 AM
Last Post: bourd
[PHP] by SLAPYAAug 16, 2010 12:04 PM 5 294 Aug 16, 2010 12:04 PM
Last Post: RadarX