DynamoGeek

    I was recently writing a bit of code where I needed to find the number of occurrences of many different substrings in a long string. Think finding a three to five word phrase in an entire book. After some profiling and fixing a few other issues, it became apparent that calling substr_count a hundred thousand times was eating the lion's share of the execution time.


    So I started looking into it a bit. I didn't quite know where to look, what with a native PHP function generally being the fastest way to do things. After trying a couple things that didn't pan out, I thought "well, I've tried everything else, might just as well check to see how a regex compares". And to my significant surprise, preg_match_all is far faster when finding substring occurrences in longer strings.


    As an example, a test script I wrote shows that using preg_match_all instead of substr_count takes about one fourth the time. If you'd like to see the test script, it's part of my PHPPerformanceExamples repo on

    Read More

    Hello again, my DynamoGeek friends!


    I'm going to forego most of the time consuming fancy words today and just dump some (hopefully) useful information.


    I had need to access a website via cURL through a VPN using PHP. Though my specific current VPN of choice is NordVPN, theoretically this information could be applied to any SOCKS based VPN service that requires authentication.


    To help out those in the back of the room, and the search engines, I'll summarize what I did more concisely. I wrote some spiffy PHP code that proxies requests for webpages through NordVPN using cURL.


    Read More

    Recently my team at work spent some time looking into the performance of our PHPUnit test suite. One of the things we wanted to improve was the rather lengthy code coverage execution time, as the suite recently crossed the 12 minute code coverage execution time threshold on our local machines. When it takes this long to generate a code coverage report, you just really don’t want to wait every time you have a feature to commit. As I’m sure you’re much more interested in how to decrease that coverage time, I’ll get right to it.


    We did two things to decrease the execution time:

    • Updated to PHPUnit 7.4
    • Used a new feature available in PHPUnit 7.4 to offload the file whitelist to XDebug
      • This uses a feature that is only available in XDebug 2.6+

    If you’re currently using PHPUnit7.4+ and XDebug 2.6+, or can upgrade to them, you can probably save a solid chunk of time.


    Starting with PHPUnit 7.4, a couple great improvements were made related to code coverage execution time. First, they made

    Read More