Handling large files with(out) PHP

As one man was quoted "640K of memory should
be enough for anybody" no one will need to access more than 2 GB data. What happens if you – just for scientific reasons of course – try to access larger files using your 32bit hardware and your favorite programming language PHP? For a first test let’s take this file

$ ls -hl dummyfile
-rw-r--r-- 1 johannes users 2.2G 2006-02-02 14:32 dummyfile

and a bit code, to read the first few bytes of it

$fp = fopen("dummyfile", "r");
$data = fread($fp, 255);


Now, time to run the script, but first let’s think what the right behavior is. In this case it’s quite simple, we just expect an empty page. So let’s see:

Warning: fopen(dummyfile): failed to open stream: File too large in ....


Zend Studio goes Eclipse

After Zend announced to enter the Eclipse Foundation one expected Zend to give up their own Zend Studio and integrate it with the Eclipse Framework. A small update in a recent blog posting from Sebastian gives a few details about Zend’s plans.

According to this proposal Zend is working, together with IBM, on an Eclipse-based open source PHP development solution. This would combine Zend’s great (remote) debugging facilities with an quite advanced IDE and solve the biggest problem of the current Zend Studio: The bad editor. According to the proposal they plan to release a preview at Q1/2006 which fits perfectly to the scedule of the EclipseCon 2006 where Andi Gutmans from Zend and Stewart E. Nickolas from IBM are giving a talk about their PHP IDE Project. So let’s see what they’ll have till then.

Meet me at php|tek

php|tek, the next conference from the php|arch
guys around Marco Tabini who already organized the php|cruise and php|tropics
conferences, will be from April 26th to 28th at Orlando, Florida. As
you can read on the recently published schedule
I’ll hold two talks. The first talk will be about PHP on the command
line, showing PHP’s strength beyond the web which can be helpful to
build, deploy and scale your web-application and even for building apps
completely independent from anything on the web. My second talk will be
about PHP’s reflection API. In that session I’ll give an introduction
into the API and show how to use it to build modular, dynamic

If you’re in reachable distance you should take the chance to listen and meet PHP developers from all over the world. (Hint: Till January 31st you can get early-bird rates!)


The truth about Rasmus the Lamer

Rasmus made us think he was doing great work by developing PHP. But as you already could read in this mail a PhD(!) found out the truth about Rasmus: His stuff „is total crap“ and he isn’t „fit to write a single line of code“. That mail even includes some good advices for Rasmus, for example to „at least take the time to research [the] basics“.
Now this point of view started to become widespread: even the organizers of the Free and Open Source Software Week in Sri Lanka found out the truth about PHP’s father: His actual name is not Lerdorf but Lamersdorf. And understanding German you know that „Dorf“ means village, so in reality Rasmus is some lame village guy not made for the big open source world!
Sorry guys, move along, this PHP is just a buzzword…
(thank’s Andrei and Johann for these links)

More PHP power on the command line

If you use PHP on the command line you most probably know the -r parameter to execute one line of code. This feature is quite nice but it’s hard to keep the quoting right. Depending on which quotes (single or double) and shell you are using you might even need to keep attention on escaping variables. Writing the code directly to the STDIN of a php instance is quite annoying if you just want to change something after typing it. Always writing the code into a file (even so it’s just a single line + <?php) and running this file is quite circumstantial. To solve this problem Marcus and I were adding a new feature to PHP 5.1’s CLI SAPI whicht I’d like to introduce here: An interactive PHP console.



In a recent discussion on the PHP internals list Andi asked why ReflectionClass::getMethod() throws an exception when the requested method doesn’t exist instead of returning NULL. During the discussion it came out that it brings advantages to throw an exception when doing things like $class->getMethod(‚foo‘)->isInternal(); or if you really like exceptions. In addition it brings consistency with ReflectionMethod’s constructor which throws an exception too when a method can not be found. But since exceptions aren’t a good instrument just to check wether a method does (not) exist the conclusion was to add a ReflectionClass::hasMethod() method which simply returns a bool. Since I’m currently learning how this PHP stuff works I wrote a patch which was committed by Marcus this morning.

Is this negative? (or need for speed #2)

As Pierre wrote before sometimes you need functions you usually would say "no, you’ll never need this, this task can be done with just one line PHP" but later you see "Okay, now I could use it".

We had such a situation a few days ago: Thorsten once complained that PHP has functions for everything but no is_negative(). We all in the office, including Pierre, knew that we don’t need such a function since everybody should be able to do this using the < or > operators and would neeevvveeeerrr demand it. A few weeks later, Thorsten and Pierre are working on a project where they are doing some complex calculations and Pierre recognizes the need for such a function. As a result I can present you our companies new friend: is_negative().