Month: December 2007

Being Binary in SOAP

Well, it might not be the best way to do it, but here’s a way I found to send binary data via PHP’s SOAP extension from one place to another:

Server:

function recieveFile($data){
	$data=base64_decode($data);
	$path='/my/file/path/img_out.gif';
	$fp=fopen($path,'w+');
	if($fp){ fwrite($fp,$data); fclose($fp); }

	return strlen($data).' written';
}
$input	= file_get_contents("php://input");
$server = new SoapServer(
	'http://[my url here]/binary.wsdl',
	array('encoding'=>'ISO-8859-1')
);
$server->addFunction('recieveFile');
$server->handle();

and the Client:

ini_set("soap.wsdl_cache_enabled", "0");

//send binary data
$client=new SoapClient(
	'http://[my url here]/binary.wsdl',
	array('encoding'=>'ISO-8859-1')
);

$data=file_get_contents('/my/file/path/img_to_send.gif');
$ret=$client->recieveFile(base64_encode($data));
print_r($ret);

It’s pretty basic – the client just reads in the file’s information, runs it through a call to base64_encode before it’s sent off to the server. Once it’s there a mirror call to base64_decode gets the content back to normal and it’s written out to the “img_out.gif” file on the remote server.

It’s probably not the best way to do it, but its one that I’ve found that works quickly and easily. I tried to just send the binary data without base64 encoding it and it didn’t want to cooperate (it was only getting the first chunk of data). I don’t know how well it’ll perform with larger files, though – we shall see.

Advertisement

My Day of Advent – Dec 10th

Lookit! It’s me!

Chris has posted my contribution (self-promotion?) to the Advent Calendar for this year – my (not so brief) look at planning your applications. Thanks to Chris for including me on the list for this year’s calendar (there’s going to be more, right?)

I got to try out the new photo editing in Flickr to make the picture for it – works pretty well for being web-based.

In the way of a personal plug, besides the holiday themed calendar version of each of the days that Sean’s created, I’ve also been keeping up with each of them in a post over on PHPDeveloper.org.

28 Days Later

Well, unfortunately, this year’s Nanowrimo has come to an end and I’m just over the halfway mark on my “piece of literature”. I started a little late – the 2nd – so it’s been a catch-up game since. It’s been an interesting experience so far and different than I thought it would be. I suppose I’m too used to writing to more technical things – tutorial copy only has to explain what’s already there – and not things that are plucked right out of nowhere. I can do short fiction (have in the past, at least) so I thought I’d try my hand at taking the month to work up what I could. I only really got the chance to work on my lunch breaks, so I didn’t think 27k-ish was too bad.

So anyway, here’s a few things I’ve learned from the experience. I thought they might be helpful to someone out there:

  1. Planning is sometimes not such a bad thing
  2. Working with two or three major characters is much easier than six or seven
  3. It’s okay to kill people off
  4. Stick with a concept – don’t write to write to whatever comes to mind
  5. Write where and when you feel comfortable
  6. Know what you’re talking about – readers can tell when you’re faking it
  7. Yes, it’s a lot of work, otherwise everyone would do it

Having been on the other side of writing – doing technical stuff – it’s funny to see how many of these same things apply there as well. Well, okay…with the exception of a few. It’s been an interesting experience and I’m going to go as long as I can on what I’ve come up with so far (27k+ words) and I’m going to keep updating my count on the right to keep up with it. I figure that if it took me about a month to get here, I can get a lot done in December and maybe hit the 50k+ mark by the beginning of next year.

Oh, and Elizabeth, you’re not giving up either 🙂