What are good book/tools/approaches/practices in order to optimize and/or test PHP7 code?

I am doing some small research on that so any idea would be useful.

  • 5
    Inb4 someone says do not use php7 to code
  • 2
    I can recommend PHPUnit for unit testing.

    Go with Composer dependencies and use an OOP approach (with namespaces & composer autoloading).

    Use PHP 7.1 or higher.
  • 3
    Common sense and understanding of what goes on beneath.

    PHP is an interpreter. It reads the script as text, passes it into an instruction tree, and executes it.

    The hey to performance is to minimize the tree. Ex. Don't include every file from the project for a simple task. Learn what lazy loading is, apply it everywhere. Only load stuff when it's deemed necessary.

    I haven't coded PHP for a while, so maybe its pipeline had changed with FPM it whatever, but these principles are the same for every platform.

    Load as little as you can get away with, then make the loaded code faster by coding smart (data processing in the DB and not PHP, associative arrays versus lookup in long arrays, regex only when simple string operations can't cut it, etc).

    And through it all ... CACHING. Cache every result that is used more than once.

    Basically.. performance .. learn to tell the computer to do as little as possible, to give you the stuff you want.

    There are libraries for most of it usually.
  • 2
    Start here

    And here

    Get familiar with phpunit

    If you use Git, look into having the pre-commit hook run your unit tests - basically call an phpunit with the XML suite and it will return true/false to allow/block the commit, this will prevent you committing broken code.

    Unless you have a solid reason to be using PHP5x (legacy codebase), use PHP7

    Good luck on your journey.
  • 2
    @C0D4 PHP 5.6 will reach End of Life this 31. December 2018. And 7.0 in 3. December 2018.

    Any project that still does not support PHP >=7.1 is utter bullcrap.
  • 2
    @PonySlaystation hey don’t talk to me about utter bull crap, I still maintain a 4.3 project 💩😔💀🔫

    Why, because it’s cheaper to maintain it then to rebuild it - especially when it doesn’t undergo any development but it does it’s job well.

    Any project not using 7, was built before 7 was released. the business probably doesn’t want to invest in the migration time since “it works” as is, now I’m not saying thats Right or the correct attitude to have, but it is what it is.

    On that note, if anyone starts a new bloody project below v7 - you had better be explaining yourself to the gun in my hand.
  • 2
    My condolences...
    These companies are probably the same who still use Windows XP.
  • 2
    @PonySlaystation actually I’m doing everything I can to decommission it, I’m almost tempted to just pull the plug and let it be the end of it.

    It’s old, it’s vulnerable and it has to run in a DMZ - apparently that’s not enough 🤷‍♂️

    But yes, in principle I agree don’t use anything below 7 where possible.
Add Comment