Category: php

  • Fixing REMOTE_ADDR when behind a proxy/varnish server

    I had an annoyance where varnish proxy infront of a LAMP server and the LAMP server therefore thought all clients were from the varnish proxy – rather than the client’s real IP address – i.e. $_SERVER[‘REMOTE_ADDR’] was set to the IP address of the Varnish proxy and not that of the client’s actual IP address.…

  • Checking PHP code for compatibility issues

    One project I occassionally hack on is Xerte Toolkits. Yesterday on the mailing list it came up that someone was trying to use XOT with PHP4. After getting over some initial shock that people still use PHP4 (it was end-of-lifed in August 2008) I wondered how easy it would be to check the status of…

  • Netbeans vs Vim … round 1 … fight

    So, I think I’ve changed ‘editor’. Perhaps this is a bit like an engineer changing their calculator or something. For the last 10 years, I’ve effectively only used ‘vim‘ for development of any PHP code I work on. I felt I was best served using something like vim – where the interface was uncluttered, everything…

  • A week of fire fighting (aka why you should <3 unit tests).

    I feel like I’ve spent most of this week debugging some PHP code, and writing unit tests for it. Thankfully I think this firefighting exercise is nearly over. Perhaps the alarm bells should have been going off a bit more in my head when it was implied that the code was being written in a…

  • SQL Injection with added magic_quotes assistance (the joys of legacy code maintenance)

      Sometimes you really have to laugh (or shoot yourself) when you come across legacy code / the mess some other developer(s) left behind. (Names slightly changed to protect the innocent) class RocketShip { function rahrah() { $sql = “insert into foo (rah,rahrah,…) values ( ‘” . $this->escape_str($this->meh) . “‘, …… )”; mysqli_query($this->db_link, $sql) or…

  • Zend_Cache – automatic cache cleaning can be bad, mmkay?

    $customer uses Zend_Cache in their codebase – and I noticed that every so often a page request would take ~5 seeconds (for no apparent reason), while normally they take < 1 second … Some rummaging and profiling with xdebug showed that some requests looked like : Note how there are 25,000 or so calls for…

  • PHP Serialization & igbinary

    Recently I’ve been trying to cache more and more stuff – mostly to speed things up. All was well, while I was storing relatively small numbers of data – because (as you’ll see below) my approach was a little flawed. Random background – I use Zend_Cache, in a sort of wrapped up local ‘Cache’ object,…

  • Gregynog

    Once a year, Aberystwyth’s Computer Science department take their second year students to Gregynog, for the purpose of preparing them for job interviews (mostly for the upcoming industrial year placements many students take between years 2 and 3). I’ve attended this for the last few years as an ‘Industrialist’ and help run mock interviews. Initially…

  • Late to the performance party

    Everyone else probably already knows this, but $project is/was doing two queries on the MySQL database every time the end user typed in something to search on to get the data between a set range (SELECT x,y….. LIMIT n, OFFSET m or whatever) and another to get the total count of records (SELECT count(field) ….).…

  • Logging … and how not to do it.

    Grumpy man, back from battling with some legacy code, has a rant.