Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,304 members, 7,954,231 topics. Date: Friday, 20 September 2024 at 02:57 PM |
Nairaland Forum / Science/Technology / Programming / Some optimization tips for php (882 Views)
Bincom Academy 95% Scholarship For PHP/MYSQL Training January Session / Help On Login Code For Php N How To Store On Data Base. / [Code Request] Code for PHP Login And Signup (2) (3) (4)
Some optimization tips for php by grandtheft: 6:33am On Sep 20, 2013 |
1) ++$i is faster than $i++. You should use this is scenarios where it doesn't matter if you do a post or pre increment, because both of they are not the same. Same applies to pre decrement and post decrement. 2)Single quotes is faster than double quote because php searches for variables in a double quote. If you don't have variables in the double quotes consider changing it to single quotes. 3) for($i = 0; $i < count($arr); $i++) { is very bad because the count function gets called on each iteration. Rather declare a variable outside the loop like this: $count = count($arr); for($i = 0; $i < $count; $i++) { |
Re: Some optimization tips for php by grandtheft: 7:02am On Sep 20, 2013 |
4)Rather than search an array for a value. Why not make the value the key then use the isset method ?. Here is what am saying: <?php $arr = array('apple' => 1, 'pineapple' => 1, 'orange' => 1, 'mango' => 1, 'pawpaw' => 1); echo (isset($arr[$_GET['fruitname']]) ? 'Fruit Found' : 'Fruit Not Found'); ?> that is better, we all know isset is very fast. That was the same technique i used to build the unofficial . 5)copying variables just because you want a shorter name is totally wrong. Except you have a reason, because it consumes more space for nothing. |
Re: Some optimization tips for php by spikesC(m): 11:06am On Sep 20, 2013 |
Do not use classes everywhere, even though you don't need them, just cos u wanna go OOP. Including files and using classes are very resource intensive operations. 1 Like |
Re: Some optimization tips for php by Nobody: 2:25pm On Sep 20, 2013 |
spikes C: Do not use classes everywhere, even though you don't need them, just cos u wanna go OOP. you can use the SPL Autoloader and Namespaces, they only get triggered when a class is instantiated |
Re: Some optimization tips for php by CHARLYX9: 3:25pm On Sep 20, 2013 |
pc guru:Recommend 6 good beginners php book for me with 840 pages abeg. |
Re: Some optimization tips for php by Nobody: 3:34pm On Sep 20, 2013 |
CHARLYX9:Why do you need six and why the emphasis on pages, i used only one book Php 5 power programming it takes on advanced php and oop 1 Like |
Re: Some optimization tips for php by Ajibel(m): 4:41pm On Sep 20, 2013 |
CHARLYX9: |
Re: Some optimization tips for php by spikesC(m): 2:57am On Sep 21, 2013 |
pc guru: The advice is not to use classes at all when it's not necessary. BTW, the SPL Autoloader is even worst, talking about resource usage. |
Re: Some optimization tips for php by Nobody: 5:20am On Sep 21, 2013 |
spikes C:so if am to understand you, in order to gain performance i should write all my codes in one file and not use classes, no thanks __autoload and SPLAutoloaders only activate when a class is called, i haven't encountered any performance issue on my part here besides its PSR-0 its the standard all my projects at work are OOP anyway so i don't know much about procedural projects. |
Re: Some optimization tips for php by grandtheft: 6:47am On Sep 21, 2013 |
pc guru:he didn't say All you code. |
Re: Some optimization tips for php by Nobody: 6:51am On Sep 21, 2013 |
grandtheft: he didn't say All you code. Ok sorry i misread that ,sure OOP is not neccessary , also another tip using Output Buffering for caching puproses like Gzip and HTTP Compression, Database result cache and some others. Install APC too works also. |
Re: Some optimization tips for php by grandtheft: 8:23am On Sep 21, 2013 |
Also do not do mysql queries in a loop, you can store all the queries in a variable in the loop then do the query outside the loop |
Re: Some optimization tips for php by grandtheft: 8:51am On Sep 21, 2013 |
Use str function over most regex functions. Except you really require a regex. |
Re: Some optimization tips for php by Elvisten10(m): 5:44pm On Sep 21, 2013 |
pc guru: elvisten built the api, unless this is elvisten seun don strike lol.lmao |
(1) (Reply)
Am I Being Stalked By Nairaland? Or Is It Another Virus? / ..... / Pls Help Me Rate These Ideas!
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17 |