Results 1 to 13 of 13
  1. #1

    PHP with spaces or without spaces

    I am trying to optimize my PHP scripts to be faster and use less resources. Do spaces and line breaks in the PHP code itself increase or decrease speed and/or resource usage?
    My personal blog -- rubiverse.net

  2. #2
    Newp.

    If you were concerned about that the smart thing to do would be to use an opcode cache like xcache or something and it'd render it irrelevent, but short of it being extra data to read through which obviously has an effect - but minimal - no.

  3. #3
    Join Date
    Dec 2002
    Location
    India
    Posts
    1,433
    PHP with spaces or without space
    Irrespective of it's effect on php execution speed, it will surely reduce the readability speed
    Chris, Developer/Programmer,
    https://www.chrisranjana.com/
    Php laravel developers, Node Python developers,
    AWS Certified | Python developers | Nodejs Developers | Devops

  4. #4
    Join Date
    Oct 2010
    Posts
    220
    Check this out :

    http://www.joomlaperformance.com/art...s_43_14_2.html

    I found some interesting things there like:

    echo is 5% faster than print()
    'String' is 0.26% faster than "String"

  5. #5
    Join Date
    Sep 2004
    Location
    Cluj-Napoca, Romania
    Posts
    504
    Is it the PHP itself speed execution that you want to optimize?

    Database queries are usually the ones that are slowing PHP scripts and optimization for this is usually done on the database side and not in the PHP code.

  6. #6
    Join Date
    Apr 2011
    Location
    Melbourne
    Posts
    93
    Use an opcode cache, optimise your database queries and try to include as few files as possible to reduce disk IO. Those three in themselves will create genuine performance gains... removing spaces from a file won't even make a blip on the radar.

  7. #7
    Think I said that already.

  8. #8
    Quote Originally Posted by ketan View Post
    Use an opcode cache, optimise your database queries and try to include as few files as possible to reduce disk IO. Those three in themselves will create genuine performance gains... removing spaces from a file won't even make a blip on the radar.
    My hosting provider doesn't use Opcode caches, but I will do all the other suggestions. Thanks
    My personal blog -- rubiverse.net

  9. #9
    If they do any amount of PHP hosting at all it's highly recomended - maybe you can suggest they do and get some brownie points

  10. #10
    Join Date
    Jan 2004
    Posts
    593
    Quote Originally Posted by streaky81 View Post
    If they do any amount of PHP hosting at all it's highly recomended - maybe you can suggest they do and get some brownie points
    Half the hosts out there use SuPHP. They don't have much of a choice.

    As for optimization. It's all in the coding techniques and your knowledge of the built in functions that php provides.

    Spacing is ignored as are comments, however, the smaller the file the faster it will be read.

    I suggest looking into a few books by Larry Ullman. He is a great author and easy to follow.

  11. #11
    And half don't

    Seriously though that's an issue but it's worth mentioning.

    Opcode caches are useful for a whole bunch of issues that can't be solved with code optimisation alone.

  12. #12
    Join Date
    Jan 2004
    Posts
    593
    Quote Originally Posted by streaky81 View Post
    And half don't

    Seriously though that's an issue but it's worth mentioning.

    Opcode caches are useful for a whole bunch of issues that can't be solved with code optimisation alone.
    What issues are you referring to that optimization cannot handle? I understand what caches are for and understand the purposes to handle heavy traffic, but what other issues are you leading to?

  13. #13
    My host uses LiteSpeed lsapi php suexec, if that helps.
    My personal blog -- rubiverse.net

Similar Threads

  1. PHP Function spaces not allowed(Newbie question)
    By bambinou in forum Programming Discussion
    Replies: 5
    Last Post: 01-22-2011, 01:37 PM
  2. PHP: Breaking long text (w/o spaces)
    By krissauquillo in forum Programming Discussion
    Replies: 4
    Last Post: 12-22-2007, 12:06 AM
  3. PHP/MySQL script keeps adding blank spaces to the database.
    By Mark226 in forum Programming Discussion
    Replies: 8
    Last Post: 09-26-2005, 04:29 AM
  4. Ad spaces available
    By Dec in forum Other Offers & Requests
    Replies: 2
    Last Post: 11-01-2003, 10:30 PM
  5. php help, removing spaces
    By matt2kjones in forum Programming Discussion
    Replies: 15
    Last Post: 09-29-2003, 02:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •