Pragmatism in the real world

Debugging PHP SOAP over SSL using Charles

I'm currently integrating against a SOAP server using PHP which wasn't working as I expected, so I wanted to find out what was happening over the wire. I have Charles installed and use it regularly with OS X's system-wide proxy settings. However, PHP's SoapClient doesn't use these, so I had to work out how to do it manually. Enabling SoapClient to send via a proxy is really easy and is documented by Lorna Mitchell in… continue reading.

Selecting the service port with PHP's SoapClient

I'm currently integrating with a SOAP service which has two different services defined. The relevant part of the WSDL is: <wsdl:service name="Config"> <wsdl:port name="BasicHttpBinding_IConfiguration" binding="tns:BasicHttpBinding_IConfiguration"> <soap:address location="http://nonsecure.example.com/Configuration.svc"/> </wsdl:port> <wsdl:port name="BasicHttpsBinding_IConfiguration" binding="tns:BasicHttpsBinding_IConfiguration"> <soap:address location="https://secure.example.com/Configuration.svc"/> </wsdl:port> </wsdl:service> I discovered that PHP's SoapClient will select the first port it encounters and doesn't provide a way to select another one. This was a nuisance as I wanted to use the SSL one. Through research, I discovered that I can… continue reading.

Testing my ZF1 app on PHP 7

Zend Framework 1 is still actively maintained and we fully intend to ensure that ZF1 works with no problems on PHP 7 when its released. Now that PHP 7.0.0 Alpha 1 has been released, it's time to find out if your Zend Framework 1 app works with it. The easiest way to do this is to use a virtual machine. My preference is Vagrant with Rasmus' PHP7dev box. A simple VM I wanted to test… continue reading.

20 years of PHP

Today marks 20 years since PHP was released by Rasmus Lerdorf and Ben has been asking for how we started our PHP journey. My first use of PHP was to write a website for an online computer gaming guild for EverQuest, back in 1999. A friend recommended it when I asked him how people programmed webpages in something other the C! That first website is still going and I'm not proud of the code. I'm… continue reading.

My Xdebug configuration

With the release of Xdebug 2.3, I have updated my xdebug php.ini settings, so it seems sensible to write them down where I won't lose them! The new-for-2.3 features which prompted this are xdebug.overload_var_dump, which Derick has written about and xdebug.halt_level which I have previously written about. I find both of these very useful. This is my current php.ini configuration: ; Xdebug settings ; var_dump() displays everything, including filename and line number xdebug.overload_var_dump = 2… continue reading.

Turn warnings into exceptions

As I keep looking this up in other projects that I've written, I'm putting it here so I can find it more easily. There are a number of built-in PHP functions that generate a notice or warning that you can't turn off when something goes wrong, such as parse_ini_file and file_get_contents. One common solution to this is to suppress using the @ operator: $result = @file_get_contents($url); if (false === $result) { // inspect error_get_last() to… continue reading.

Building and testing the upcoming PHP7

The GoPHP7-ext project aims to ensure that all the known PHP extensions out there work with the upcoming PHP 7. This is non-trivial as some significant changes have occurred in the core PHP engine (related to performance) that mean that extensions need to be updated. In order to help out (and prepare my own PHP code for PHP 7!), I needed the latest version of PHP7 working in a vagrant VM. Fortunately Rasmus has created… continue reading.

Convert PHP Warnings and notices into fatal errors

Xdebug version 2.3 was released last week and includes a feature improvement that I requested back in 2013! Issue 1004 asked for the ability to halt on warnings and notices and I'm delighted that Derick implemented the feature and that it's now in the general release version. It works really simply too. Turn on the feature by setting xdebug.halt_level either in your php.ini or via ini_set(): <?php ini_set('xdebug.halt_level', E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE); Now cause a warning: <?php echo… continue reading.

Sending test emails from PHP

I've written before about redirecting email while developing using a trap mail script on my development system. Other people also like MailCatcher. I've recently switched to using a simple PHP script that creates a elm file on disk that can be opened by Apple's Mail client. This solution is much faster as there is no SMTP processing involved. Adam Royle came up with this solution in his article Setup a testing mail server using PHP… continue reading.

Setup Doctrine Migrations to update MySQL timestamp on update

One project I'm working on uses MySQL exclusively and is also using Doctrine Migrations. I wanted to set up a column called updated that was automatically set to the timestamp of the last time the row was changed. This is done in SQL like this: CREATE TABLE foo ( id INT AUTO_INCREMENT NOT NULL, bar VARCHAR(100) NOT NULL, updated timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY(id) ); It's not quite obvious how to do… continue reading.