test.ical.ly | getting the web by the balls

TAG | Stream Wrappers

I’ve written the StreamHitching library to ease the process of writing mockable and analysable stream wrappers and in the last few weeks I have used it in some projects at work.

One of these projects uses StreamHitching to communicate with a web service. The web service however didn’t prove to be too reliable and sometimes failed to respond.

In order to avoid the client to wait forever and eventually die due to the max_execution_time limit I needed to introduce a way to set a timeout.

The result is simple and effective and also allows fancy stuff such as HTTP authentication. :)

(more…)

· · · · ·

presentAs I mentioned before I am working on a small framework to implement custom stream wrappers.

For example you can later use this to easily wrap access to a web service or similar.

As of today I reached a 90+% code coverage and everything passes. Check out the sources and see if some test does not work for you.

(more…)

· · · · · · ·

field-book-of-ponds-and-streamsIn the last couple of months I have occupied myself a lot with unit testing. Once you get the hand of it it starts to feel natural and easy and you don’t want to miss it any more. Testing rocks!

Another thing I worked with are PHP streams which IMHO is one of the most underrated features of PHP.

Naturally I want to test my stream wrappers with PHPUnit just as I would test everything else. But it’s not that easy..

(more…)

· · · · · ·

local-and-remoteSo I keep working on StreamHitching my little standalone stream wrapper framework and things seem to become even clearer yet.

So far I planned to incorporate two major stream wrappers; one for local files and another for remote files. I thought this is necessary as some PHP file functions can nor work on streams (such as stat()) so you have to fake them which for my purpose is good enough.

However there are some PHP internal things going on that let me reconsider and weight the options. There are 2 1/2 options as far as I see it. (more…)

· · · · · · ·

hitchhikerAfter yesterdays post I continued to think about decorating stream wrappers.

In sfImageTransformExtraPlugin I use several stream wrappers to work with  a custom URL (i.e. sfImageSource://parameters/go/here) in the application while internally working with either a local file URL or a remote one.

This works pretty well so far however I am not totally happy with some couplings in the implementation and I don’t feel that the concerns are separated well enough. But I’m quite sure that yesterdays idea can help here a lot! (more…)

· · · · · · ·

hijackBy now some of you will have realised that I like PHP stream wrappers a lot. When I started to work on sfImageTransformExtraPlugin I soon realised that stream wrappers are a very sexy way to make sfImageTransformPlugin work on all kinds of resources.

But how do you go on about writing a stream wrapper for your requirement? A lot of PHP functions work on files but it isn’t documented what internal calls are made.

To solve this you can hijack a stream with a decorator telling you all about the actual stream access.

(more…)

· · · ·

the answer to life, the universe and everythingThose of you who followed me on my sfImageTransformExtraPlugin can guess that I like PHPs feature of stream wrappers.

This feature is very underrated and underused and it could probably solve a lot of requirements with a minimum of code. So is it a good idea to use it for everything?

(more…)

·

Apr/10

14

How Microsoft saved the day!

Don’t hesitate to read this. I am not going to glorify the beast. This is foremost about the goodness of Open Source! ;)

Yesterday I received a bug report for my sfImageTransformExtraPlugin and in the end I found the error with the (indirect) help from Redmond.

(more…)

· · · · ·

Theme Design by devolux.nh2.me