Hack Forums
[PHP] How to increase performance of PHP! - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] How to increase performance of PHP! (/showthread.php?tid=3934052)

Pages: Pages 1 2


How to increase performance of PHP! - VladHQ - Dec 17, 2013

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!




* - DJSanderrr - Dec 17, 2013

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


* - t0rch - Dec 17, 2013

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 🀝


* - badbrains - Dec 17, 2013

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.


* - VladHQ - Dec 17, 2013

(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)Wolf Haley 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)BinKill-Ethical 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.


* - badbrains - Dec 17, 2013

(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.


* - VladHQ - Dec 17, 2013

(Dec 17, 2013 01:20 PM)Wolf Haley 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.


* - VladHQ - Dec 20, 2013

I would live to hear some more feedback on this tutorial!


* - Mafugsa Bob - Dec 21, 2013

(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)Wolf Haley 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.


* - VladHQ - Jan 1, 2014

(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.


* - Skidrowz Heir - Jan 2, 2014

nice info man . already bookmark :)


* - Аrthur - Jan 2, 2014

(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


* - VladHQ - Jan 2, 2014

Thanks for the feedback, guys, I really appreciate it.


* - VladHQ - Mar 7, 2014

Hate to see this thread go dead, I worked on this for a couple hours.


* - ASDA - Mar 8, 2014

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.