Discussions

Hey all here I am going to write some tips to improve the performance of php script. You can also share your thaughts related to the performance improvement in php only.

------------------------------------------
Here are some of the Tips and tricks which can improve the speed and performance of your php script and may save your resources.(NOTE:I haven't tested all these tips but these are wildly used to improve the performance of the php script.)

1.string concatenation
------------------------
echo 'php', 'developer'; // saves overhead time for string concatenation.
echo 'foo' . 'bar'; // slower..

2.Interpolation
---------------------------
$variable = 'this is '.$another_var.' with me'; // faster
$variable = "this is $another_var with me"; // slower

Reply

User Comments

  1. satijournal
    Yes, single quotes are faster because the interpreter doesn't parse the text.
    1. roy123
      Here is a cool way to stop / avoid user to directly access to our configuration php scripts or important include files.

      // this is first code block
      if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME']))
      {
      exit('This file can not be accessed directly...');
      }
      // protected code below this.


      complete post here > php-tuts.blogspot.com/2009/05/how-to-avoid-direct-access-to-file.html
    2. codesucker
      Roy, good tips - I didn't know about the double quotes slowing down the script.

      Let me know when you have new posts or information to read. Throw up an avatar and stop by the boards more often I want to pick your php brain.

      Thank you also for this code snippet.. is there a way for people(hackers) to d/l .php files from my server?? That would be troubling since the mysql database passwords are in those files.
    3. satijournal
      I use classes for everything outside of the index.php file. Using classes protects things like config files because they don't execute without being instantiated.
  2. roy123
    yes you are right satijournal, In MVC architecture of programming we don't need take care of the direct access to our configuration file but its really useful when you are doing procedural programming..

Add Your Comment

Login to leave a message.

  • Recent Readers

    • johnbeki
    • PetLvr
    • jokesadda
    • satijournal
    • codesucker
    • husdal
    • Xight
    • gtally
  • Discussion Search

  • Subscribe via Email