Singleton is bad !!

An interesting suggestion emerged from some speakers (1 and 2) of the last PHP UK conf is: do not use the Singleton design pattern !!

At the beginning it made me a little astonished as it’s one of the most widely used design patterns, in addition ZF and lots of other projects use it. However, after a while I agreed the idea. Singleton actually had created some problems when I had to do some class testing and refactoring in some PHP code.

Why is it not a good practice ? Singleton is appropriate when dealing with threads (JAVA, C#), but as a matter of fact in PHP applications it’s used just as a global constant and it creates dependency injection. That’s a bad practice as it couples the components/classes and usually makes difficult unit testing, refactoring and structural changes.
Continue reading

PHP UK conference 2010 talks

I attended the PHP UK conference 2010 on Friday. Unfortunately the event took place in one day, so there were three talks at each time slot in different rooms. I had to choice the most promising each time. It was a pity to have some very interesting ones at the same time (like AntiPHPatterns and RDBMS, or DB optimisation and the PHP 5.3). Fortunately, I’ve already found almost all the slides and notes online.
I choose the excellent PHP-strictly-related talks of S.Priebsch, F.Potencier and J.Schl├╝ter as well as the good Seguy’s talk about security (and the quite unsatisfying Hudson’s talk).
Some interesting comments on joindin. Continue reading

Upload a tree of files and subdirectory to a remote FTP server

I’ve recently been asked to move a site (1Gb of files) from a Italian hosting linux (no ssh) to the same cheap hosting but to another server windows (damn ! no ssh, no console commands from PHP, the only way to upload files is the old slow uncool FTP).

Problem: I’ve got an extremely poor upload bandwith in my house in UK. So, I’ve used another hosting with SSH (dreamhost, in US) and:
1) got data from the 1st hosting (step1). Uploaded a php files that runs “tar -cf all.tar *”m, executed a “wget” to get the tarball, extracted the tarball.
2) uploaded to the second Italian windows hosting (step2).
ncftpput -R -v -u “username” ftp://ftp.site.it /fpt-root-folder .

UPDATE: To download the site recursively: use ncftpget. Digit “ncftp” and press “tab” to see other commands

Weird tricky situation, isn’t it ?

PHP and scalability

As PHP is becoming a widely used web server technology, more and more developers are comparing PHP with other technologies like J2EE or .NET.
It has been the butt of criticism as considered not scalable: totally wrong !

A system is scalable when is able to keep the performances under an increased load, mainly due to more users. Speaking about scripting execution velocity (that is a constant in that evaluation) is a completely different kettle of fish.

So, PHP, Python and Perl absolutely scale as J2EE/.NET if the server is upgraded or more parallel servers are added.

Note that all the session-related problems (sticky sessions etc..) are managed in a lower layer, so PHP has no problem with that.


An interesting book about scalability is :Building Scalable Web Sites – written by Cal Henderson, the chief software architect of Flickr (built with PHP)