Code Monkey
Random blurps and rants about programming-
Webservices make everything easy
Posted on June 6th, 2009 No commentsScenario: PHP application has to use a couple of Webservices provided bei .NET/C#/IIS/whatever.
Should be easy, right? Not when you have to login with a separate webservice call to use the services you really want. This little fun thing requires the client to actually process cookies. Which the PHP SOAPClient does surprisingly well, without brute force required. But the server kept loosing the session sometimes. We tried different PHP versions, different operating systems, different internet connections, hell, I even hacked together a client in Java.
Then we finally figured it out: the server didn’t care if the Client says he only speaks HTTP 1.0, the server just asumed HTTP 1.1. Which essentially requires to make all the webservice calls over the same TCP connection. This is where it gets tricky.
The PHP SOAPClient allows you to reimplement a method named “__doRequest”, which does the actual network operations. So we took a HTTP 1.1 compliant connector (Zend_HTTP_Client), and implemented the request handling with it. Should be fine now, right?
Guess again, now we are actually getting to the strangest part. For some Reason, die SOAPClient crashed PHP right within __doRequest. While trying to debug it, I discoverd something REALLY strange. Tho following code, added to __doRequest, makes PHP crash less often:
ob_start();
print “abc”;
ob_end_clean();And to make it even stranger, if you replace the “print” with an “echo”, it doesn’t help anymore. WTF?!? My guess is, that __doRequest has a memory leak under certain conditions, which lets everything else go south from there on.
PHP, Rant .NET, bug, C#m, Java, Memory Leak, PHP, SOAP, SOAPClient, Webservice -
Symfony: selectively replacing application templates with a plugin
Posted on February 15th, 2009 3 commentsAfter many headaches about how the hell I can get symfony to look for a layout or a template in a plugin directory first, so that you can selectively replace default layouts (meaning the ones in the application or module template directory) with versions provided by a specific plugin, I figured out a simple and yet elegant solution. It actually took me a few hours of crawling through symfony code to figure out that it all boils down to the application configuration.
Solution: Simply overwrite the directoy getter in the Configuration class of your application and insert your disired location at the front of the array.
class MyExampleApplicationConfiguration extends sfApplicationConfiguration
{
[..]
public function getTemplateDirs($moduleName)
{
$dirs = parent::getTemplateDirs($moduleName);
array_unshift($dirs,sfConfig::get('sf_plugins_dir').'/SomePlugin/apps/'.$this->getApplication().'/modules/'.$moduleName.'/templates');
return $dirs;
}
[...]
}
Do the same thing with getDecoratorDirs() to replace layout files. It even works for I18n, because they too use a function in sfApplicationConfiguration to get their candidate directories.
-
API broken – who cares?
Posted on February 11th, 2009 No commentsDont get me wrong, I really love the symfony PHP framework. But some things really annoy me.
For example, in late november there has been some minor bugfixing, followed by a new version release. Which broke the API of a pretty basic class for no reason (method getI18NGlobalDirs got renamed to getDecoratorDirsGlobalDirs).
But accidents can happen, I hear you say. Yes they can. The mistake got fixed 9 days later, a new Version got rolled out. Well, fixed is too much for this, it got a lillte bit less broken, (method got renamend to getI18NDirsGlobalDirs).
In late december, this has been discovered and finally fixed. No new version has been rolled out yet.
Long story short, the API is broken since november and the broken version is still the latest. Which sucks when your using the stable version in some big projects.
UPDATE:
Finally, after several months, Version 1.1.7 has been released. -
untyped duck
Posted on February 11th, 2009 No commentsWhat is duck typing? Essentialy it’s a fancy name for dirty coding style (Duck typing). Want to use the same API on multiple classes with same semantics? It’s called an interface.
-
welcome
Posted on February 11th, 2009 No commentsAs I stumble about a lot of programming-related stuff when working, I have always hesitated to post it on my personal blog, because I thought it does not belong there.
Thats where the idea came from to start another blog, this time dedicated to all programming and therefor exactly the right place for the stuff I always wanted to post. I really have no idea how often I will post or what it will be about, I guess we’ll have to wait and see .



