Uncategorized

  • microtime benchmarking measures your loop as well

    Wrapping a call in two microtime(true) readings looks like a measurement and is mostly noise: one iteration, no warm-up, and the timing includes whatever the loop and the…

  • WP_Query fields => ids when you only need the IDs

    A normal WP_Query hydrates every result into a WP_Post object and primes the meta and term caches for all of them. When the only thing you want is…

  • ss replaced netstat and is considerably faster

    netstat reads and parses /proc/net/* as text. On a box with thousands of connections that is slow enough to notice, and the tool has been deprecated in favour…

  • PHP-FPM pm=dynamic numbers come from RAM, not from taste

    The default pool ships with pm.max_children = 50, which on a small server is not a limit so much as an invitation to swap. The number should come…

  • preg_quote takes a delimiter argument

    Interpolating user input into a pattern is how a search box becomes a regular expression injection. preg_quote() escapes the metacharacters, but its default output is still not safe…

  • dump-autoload -o is not optional in production

    PSR-4 resolves a class by converting the namespace to a path and checking the filesystem. That is one or more stat calls per class, on every request, for…

  • Default parameters replace the argument-check dance

    The traditional way to give a parameter a default is x = x || fallback, which is wrong whenever a legitimate value is falsy. Passing 0 for a…

  • nth-child and nth-of-type select different elements

    :nth-child(2) means “the second child, and only match if it is also this element type”. :nth-of-type(2) means “the second one of this element type among its siblings”. They…

  • Generators keep a million-row export inside memory

    A method that builds an array and returns it holds every row in memory at once. For an export of a few hundred rows that is invisible; for…

  • pre_get_posts is the hook query_posts pretends to be

    query_posts() replaces the main query after WordPress has already run it, which throws away the first result set, breaks pagination and leaves conditional tags lying about what page…