Category: PHP

  • Negative zero – what is it?

    Computers have two ways of representing numbers: One is called sign and magnitude – usually you have one bit specifying the sign (again, most of time you have 0 for positive and 1 for negative) and the rest of the bits specify the absolute value (“magnitude”) of the number. The other is ordering the numbers…

  • Please welcome a new blogger…

    Tim Starling from Wikipedia. In his first blog post he talks about the challenges involved in running a website securely where users can upload arbitrary content. It is very cool and very frightening the same time (because it makes you wonder: how many of the web applications out there are verified to this degree). One…

  • Don’t update to PHP 5.2.7!

    Or if you updated, please update to 5.2.8, since 5.2.7 contained a security regressions!

  • Fetching files form PHP in a compatible way

    I just finished comparing a whole bunch of OS’s to determine which is the most compatible (widely available) way to fetch an external HTTP page from PHP. The winner is: fsockopen – it was available on 100% of the tested systems. I was only interested in HTTP pages, not HTTPS, so the ssl transport might…

  • Dynamic code generation in PHP

    As in most scripting languages, you can dynamically generate code in PHP. As a sidenote: the reason why it is so simple to implement dynamic code in scripting languages is that you already have the “eval” function (it is called with the script), all you have to do is to provide an interface to it…

  • Creating gradients in PHP

    A few days ago I was looking around for methods to calculate color gradients in PHP. Nothing I found seemed to fit (most of them were centered around creating pictures with GD), so I decided to roll my own. You can see the code below. There is a small test script attached to the end,…

  • Benchmark with care

    I saw this site recently: PHPBench.com was constructed as a way to open people’s eyes to the fact that not every PHP code snippet will run at the same speed This is useless! Or let me reformulate: this is misleading! For one, it uses microtime to do the benchmark, which measures physical time as opposed…

  • Subscribing to a members-only SMF forum via RSS

    This is one of those bug or feature? cases. I’m member of an online forum which uses Simple Machine Forum (or SMF for short. This is a members only forum, meaning that if you are not a member (or not logged in) you see a very little subset of the forum. Now I would like…

  • Disabling mod_deflate for certain files

    I received a question regarding my compressed HTTP post. It goes something like this: I want to use a PHP script as a kind of transparent proxy (that is, when I request a file, it downloads it from an other URL and serves it up to me), but mod_deflate keeps eating my Content-Length header. My…

  • Profiling PHP with XDebug

    Resolving performance problems is hard (even more so when you have to do so with somebody else’s code) and some clear measurements are very welcome. I tried out XDebug some years back when and it didn’t work very well back then, but the latest release seems quite good. Here is how to use its profiler:…