PHP Generators – an example

I’ve ignored generators for sometime in PHP, but recently realised why they can be quite handy 🙂 As an example, imagine you are querying a web service, which returns  data in chunks of up to 100 results….

Mockery (test doubles/mocking dependencies)

[This is a relatively old post I think I forgot to publish….] Previously, I’d only used PHPUnit’s mock implementation; however lately I’ve been exposed to Mockery. While they both achieve broadly the same result (at least from my point of view), here’s an example of how to mock dependencies with Mockery. Class to test: class… Continue reading Mockery (test doubles/mocking dependencies)

Random wordpress malware

A customer’s server was compromised ages ago with lots of lots of WordPress malware. The developers are now on top of it, thanks to a combination of : * Removing wordpress’s write permission (moving over to just use SFTP) * Adding maldet (Linux Malware Detection). * Tightening up the firewall so only incoming connections to… Continue reading Random wordpress malware

dotdeb – apt package pinning

As of last night, Debian Security released PHP 5.4.44 for Wheezy. Wheezy shipped with PHP 5.4.12 or something like that. DotDeb is currently on 5.4.43, and if you’ve been using it based on the assumption that it has a newer version of a package over Debian, then an upgrade will leave your PHP install in… Continue reading dotdeb – apt package pinning

Categorized as debian, php

PostgreSQL unbuffered queries and PHP (cursors)

From using MySQL, I’ve used the ‘unbuffered queries‘ feature a number of times. It’s where you don’t fetch the entire resultset into memory at once – which is necessary if you’re retrieving more data than you have memory available. If’s often also generally gets results/data back to you sooner.

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.… Continue reading Fixing REMOTE_ADDR when behind a proxy/varnish server

Categorized as linux, php