The Spanner logo
    • Home
    • Blog
      • Blog home
      • RSS
    • Login
    • Home
    • Blog
      • Blog home
      • RSS
    • Login
    The Spanner logo

    The Spanner
    Web security blog

    Made by Gareth Heyes
    Follow me on Twitter: @garethheyes

    Javascript for hackers!

    Hackvertor logo
    Shazzer logo
    My Github account
    Recent posts
    Introducing Feedworm: A Privacy-First RSS Reader That Lives in DevToolsSpeedy RSVP extensionAutoVaderHackvertor history and tag finderShadow Repeater v1.2.3 releaseBurp Hackvertor v2.1.24 releaseHacking roomsXSSing TypeErrors in SafarivalueOf: Another way to get thisMaking the Unexploitable Exploitable with X-Mixed-Replace on FirefoxThe curious case of the evt parameterCSS-Only Tic Tac Toe ChallengeRewriting relative urls with the base tag in SafariBypassing DOMPurify with mXSSNew IE mutation vectorHow I smashed MentalJSMentalJS DOM bypassAnother XSS auditor bypassXSS Auditor bypassBypassing the IE XSS filterUnbreakable filterMentalJS bypassesmXSSJava SerializationBypassing the XSS filter using function reassignmentRPOSandboxed jQueryX-Domain scroll detection on IE using focusEpic fail IEnew operatorDecoding complex non-alphanumeric JavaScriptHacking FirefoxDOM ClobberingBypassing XSS AuditorThe evolution of codeNon-Alpha PHP in 6-7 charsetTweetable PHP-Non AlphaMentalJS for PHPOpera x domain with video tutorialSandboxing and parsing jQuery in 100ms

    Increasing PHP performance

    By Gareth Heyes (@hackvertor)

    Published 18 years 10 months ago • Last updated March 22, 2025 • ⏱️ 2 min read

    ← Back to articles

    This is just a short post on a couple of performance increases you can do in your code that was kindly pointed out to me by WhiteAcid, when he looked through the source code of my captcha. I must admit I wasn't aware of these slight improvements and I'm sure this post will inform a few people of the potential performance gains. I've haven't done any benchmarking on the following examples so if anyone knows of a good PHP benchmarking site, please send it in and I shall include the link here.

    Conditions

    The triple equals sign increases performance because PHP performs a strict check on the two variables.

    <pre lang="php"> &lt;?php if($variable1 === $variable2) { //code } ?&gt; </pre>

    Concatenation

    I usually concat a string with the following:-

    <pre lang="php"> &lt;?php echo '<option>'.$variable.'</option>'; ?&gt; </pre>

    But a better way is to use commas to output the string because PHP only has to output it instead of using concatenation.

    <pre lang="php"> &lt;?php echo '<option>',$variable,'</option>'; ?&gt; </pre>

    Benchmarks

    I found this excellent site with some benchmark tests:- PHP benchmarks

    Also this on string benchmarking:- String benchmarks

    For vs while Loops

    Yet another benchmark, this one is quite comprehensive:- Speed freaks

    That's all for now, I might include some more examples at a later time.

    Timing class by Richard Heyes

    Timing class

    Have you got any performance tips you'd like to share? Leave a comment and I shall get in touch and choose the best ones which will be added to this post.

    ← Back to articles