Using PHP and curl with http PUT on string data

This wasn't obvious

There are various other posts on this - but mostly assuming you will put a file.

In my case I want to put the contents of a string so I needed to craete a temporary filehandle.

<?php

function put_it($url, $string) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, TRUE);
// create tempoary file handle
$oneMB = 1024 * 1024;
$fp = fopen("php://temp/maxmemory:$oneMB", 'r+');
fputs($fp, $string);
rewind($fp);
curl_setopt($ch, CURLOPT_INFILE, $fp);

Read more

Integrating Selenium and Hudson

Hudson http://hudson-ci.org/ is a continuous integration server - it runs and monitors 'jobs' in a way that is useful to regularly build software and report on any errors.

Selenium http://seleniumhq.org/ is a suite of tools specifically for testing web
applications - it tests the full website by automating the running of one or more browsers (so you can test all that pointy clicky ajaxy stuff)

Read more

Debugging SOAP with Xdebug and Eclipse

It's been a while since I've worked on a project which is providing as well as consuming web services.

In this case I need to debug incoming requests that are not initiated from with the browser (I'm using soapui as a test tool).

In order to allow Eclipse to pick up xdebug responses triggered by requests from soapui I just needed to

  • start a debuging session within eclipse as normal
  • ensure that the query string ?XDEBUG_SESSION_START=ECLIPSE_DBGP is appended to all requests by editing the WSDL file so that the address looks like

Read more

Accessing CKAN data from PHP

I've been working on a couple of open data projects recently - which has been very rewarding.

A couple of people have asked for some code so I've knocked up a quick version of the sort of thing I've been working on.

This code requires PHP 5.1 for the JSON functions but doesn't need any extra libraries (pecl_http can give better error messages but is a bit of a pain to install).

The Notes field in packages returns output in Markdown format - you can convert this to HTMl with a parser available at http://michelf.com/projects/php-markdown

Read more

Make Drush support PHP-5.1

Drupal has a fairly easy to meet set of requirements http://drupal.org/node/502452

But Drupal projects are free to set their own rules in this area and Drush has used functions only available in PHP 5.2 - as far as I can see this is just the json functions.

Frustratingly the latest version of RedHat provides PHP 5.1 and this is the second time I've run into the problem with a client who uses RedHat and understandably wants to stick to the standard packages.

Read more

Multi-threaded PHP

OK so it isn't quite multi-threaded, but forking and controlling processes in the command line environment is still pretty powerful and something I've wanted to do on a couple of occasions.

http://brian.moonspot.net/php-fork

http://us.php.net/manual/en/book.pcntl.php

Read more

xdebug and Eclipse

xdebug is an immensely powerful tool for exploring what your code really does.

You can get a long way using print_r  but ultimately this always requires that you predict the path your code will take - and the tricky bit about debugging is you need it when your predications have gone wrong.

It's generally pretty easy to set up

Read more

Things to like about Symfony so far

A few days into learning Symfony and so far I'm keen on

  • configuration check to start with
  • good MVC separation
  • ability to generate initial MVC components from a database definition
  • form validation to match database constraints
  • wrapping various HTTP functions and globals in a request and response object
  • separate dev and prod environments
  • ajax integration - like defining a div as draggable in PHP
  • explicit support for initial and test data

Things not to like

Read more

Practical Symfony

Well having found the Definitive Guide to Symfony a bit uninspiring I've spent a bit of time on the "Practical Symfony" book - online.

http://www.symfony-project.org/jobeet/1_2/Propel/en/

So far it's great - the first "three days" lessons went by pretty quick, and I'm glad I'd done some background reading.

Putting the two things together I feel I've probably got enough understanding  to start writing a basic app - which is exactly what I need to do to make sense of a load of reading.

Read more