Posts Tagged ‘PHP’

I write quite a lot of command line utilities in PHP and luckily PDT makes it easy to debug command line scripts.

The thing with command line scripts is that often they require parameters passed on the command line, and PDT offers an easy way to pass them when you debug a script.

Assuming you already have debugging in Eclipse working (using either XDebug or Zend Debugger, both will work with this feature), here are the steps to debug a command line script using command line parameters:

  1. Right-click the script you want to debug and select 'Debug As...' and from the context menu that appears, select 'Debug Configurations...', like this:

    PDT context menu

  2. In the debug configurations screen that appears, select the 'PHP Script Arguements' tab. In the text box that appears, you can add fixed parameters (e.g. --key=value), but it's much more useful to use Eclipse's dynamic parameters, like this:

    picture-29

    In this case I entered --visitor=${string_prompt:Visitor} which means: pass --visitor= to the script when debugging, but ask me to enter a value named 'Visitor'.

  3. You can use the 'Variables' button to enter variables like this using a more visual wizard. There are many different prompts, string_prompt is just one example; you can prompt for folders and passwords as well, and you can inject certain system variables as a parameter using this wizard)
  4. After you've saved the Debug Configurations, again right-click the script you want to debug, and select 'Debug As...' and then 'PHP Script'.
  5. Eclipse now pops up the prompt, like this:

    picture-30

Voila, you can now debug your command line script by passing in dynamic parameters whenever you start the debug session.

P.S. This not only works in Eclipse PDT but also in Zend Studio for Eclipse and Aptana (in theory, haven't tried either yet).

P.P.S. No, I didn't create a script that allows me to track individual visitors, it's an archive processor for Flackr that uses the Visitor design pattern to make it easier to write multiple processors. I love Design Patterns.

Why did the chicken cross the road?

November 9th, 2008 by Ivo

So what does the PHP community think about why the chicken crossed the road?

Lukas Smith: "We should ignore the chicken for now and make sure that the parse-ability, typeability and ide compatibility of what separates this side from the road from the other side is better than the current separator proposal." *

Zoe Slattery: "To ensure the quality of the chicken once it has crossed the road, the code coverage of /ext/road needs to be at least 80%. The chicken will test || die." *

Chris Shiflett: "The chicken should be more aware of Cross Road Scripting vulnerabilities when crossing the road like that." *

Stefan Esser: "Ze chicken needs to be protected from ze stupid dumbasses that have no clue how to secure ze road. I have demonstrated zeveral vulnerabilities in ze road before, but I was ignored." *

Lorna Mitchell: "We do NOT exlude roosters, but we need to encourage the chicken so that it knows that it is ok to cross the obviously male-dominated road." *

Terry Chay: "Fuck, is crossing the road a design pattern? Shit no, it's not a fucking algorithm either. When I blog about it, I'm, like, the guy that totally killed the fucking chicken." *

Paul M Jones: "I don't care why the chicken crossed the road, but we need to benchmark how fast the chicken crossed the road using all the major frameworks. And Chay is a bully for making it cross the road!" * *

Ivo Jansch: "Why did the chicken cross the road? [jaws]Dumdumdumdum...[/jaws]" *

Cal Evans: "Good morning twitterverse! Today is an AWESOME day for the chicken to cross the road! But if it doesn't cross the road in 60 seconds, I'll move to Holland." * * *

Paul Reinheimer: "The chicken crossed the road because I was on the other side. In my KISS outfit." *

Ligaya Turmelle: "Chicken Darlin!" (smooches chicken) *

Derick Rethans: "I debugged the chicken while it crossed the road. I will speak about the results at works, tek, ipc, phpnw, phpbarcelona, phplondon, phpquebec, froscon, phpvikinger, oscon, dpc, phpnorge and zendcon. Hey, alcohol!" * *

Michelangelo van Dam "50 chickens are marching across the road!" *

Harold Goldberg: "We are The Chicken Company. To cross the road, please enter your Zend user id and password." *

Chris Cornutt: "The chicken has posted an update on its blog today, explaining the reasons for crossing the road. Some of the reasons it mentioned are 'wanting to be on the other side', 'just because' and 'what road?'. Check out the full details in the chicken's post, as well as the community's responses to the crossing of the road here." *

Laura Thomson: "All chicken suck." *

Post your PHP community chicken theories below!

Apple, Microsoft and PHP are vulnerable

August 26th, 2008 by Ivo

I recently came across this article:

"Apple, Microsoft, PHP headline IBM's list of most vulnerable software"

This article once again demonstrates the cluelessness that some people have regarding what PHP is. First of all, PHP is not a vendor, so "Apple, Microsoft & PHP" does not make much sense. Furthermore, the only reason PHP even is mentioned in this context is that Joomla, Drupal and WordPress appear in the list. So PHP, a programming language, gets blamed for the security flaws that are in these packages.

With the same data, I might conclude that C is more insecure than PHP, after all there are more C-based vendors/product in the list than PHP products.

But they're not just clueless about PHP, they also list Linux as a Vendor in their top 10 list. Linux is an operating system, not a vendor.

Sometimes I wish these reporters would talk to people that know what their talking about before they write such an article.

Dutch PHP Conference 2008 recap

June 16th, 2008 by Ivo

The Dutch PHP Conference 2008 is over. Since I was one of the organizers, I'll leave reviews of the contents etc. up to others, but here's my look on the conference from an organizing perspective.

On friday, the conference started with a tutorial day. There were 5 tutorials: PHPUnit by Sebastian Bergmann, XDebug by Derick Rethans, Zend Framework by Matthew Weier O'Phinney, Symfony by Fabien Potencier and Stefan Koopmanschap, and Advanced PHP: Design Patterns by Dennis-Jan Broerse. The tutorial day was attended by 150 people.

The day started pretty chaotic; the van that contained the registration badges arrived late, so there was hardly enough time to prepare the registration desk, so we had a small queue, but eventually everybody got in. The other issue we had was that we had asked the venue to provide power because people would bring there laptops. We started off however with only 4 outlets per room, and with 30-40 peple in the room, that obviously is not enough. Luckily, before the first break we were able to get a whole cart with power supplies, which we hastily dropped in the rooms. It looked a bit like a cable jungle, but at least people had juice. :-)

For the rest, the day ran smoothly and according to plan, we had a nice lunch around noon, and overall feedback on the tutorial day was good.

At 17.30, we went to the Werck bar where we had dinner with the Ibuildings crew and a bunch of Zenders (Matthew, Gaylord, Zeev, Steven and Howard). At 20.00, DPC conference people started showing up at the bar for the friday-night conference social. Dinner ran a bit late but around 20.30 we were able to join the other DPC visitors in the bar, just in time for the Netherlands-France euro2008 match. The party was great, the match was superb (NL won by 4-1), and the atmosphere was awesome. Speakers like Terry Chay and Derick Rethans were dressed up in orange (Terry even had created a custom orange shirt with php code on it) and we all had a great time.

At around 23.30 I went back the hotel area with Derick, Terry, Scott, Mike, Helgi and one of the phplondon guys who's name I can't remember. Derick and Terry walked back to their hotel and I had a last beer with the other guys.

I made some final adjustments to my slides for the opening address (which for some reason is more difficult after more than a couple of beers) and at around 1.30 I went to sleep. At 6 I woke up, checked if my adjustments were ok when sober, made some more changes, went over the slides for my afternoon presentation, and got prepared for the main conference day.

The main conference day went even smoother than the tutorial day. Registration was properly prepared and went smooth, everything was nice on schedule (with just a small exception caused by a crashing macbook right before the closing keynote), and I think we were able to organize a very nice conference (feedback is appreciated!).

We had some php|architect books for sale during lunch. We had about 50 books because we had no clue if people would be willing to buy them, but we ended up selling 45 books within the first 20 minutes. We will bring a little more next year. :)

An interesting observation was that the PHP Women had trouble getting people to take their promotional shirts. Where at the PHPLondon Conference they were gone before they knew it, in Amsterdam the men were a little hesitant to wear a shirt with the word 'women' on it (by the way only 1% of the DPC audience was female, which is startling). Together with Matthew Weier O'Phinney I was selected as the girls' official 'Booth Babe', a kind of supporting role with a special edition of the shirts, but I got some really weird remarks on that. I think the phpwomen have to change their marketing to cater to a continental european audience or at least to get the men involved. (Suggestion: s/babe/hunk; babe is usually only used for the female version over here).

When the conference ended, there were drinks and snacks in the lounge, giving people the opportunity to discuss the presentations and talk to the speakers.

And then the day ended with a final speaker's dinner, and that was the end of the Dutch PHP Conference 2008.

There are already over a 100 pictures on flickr, which give a nice impression of the conference.

I'm already looking forward to organizing it again next year! (mark June 12 and 13 in your calendars!)

I just helped one of our developers with a weird problem. The piece of code he was working on contained roughly this:

 
if ($str!='')
{
   echo "Hello $str";
}
 

He was importing a CSV file that didn't contain a value for $str, so $str was an empty string. So it should skip the echo statement according to the above code, right?

Wrong. The script echoed "Hello ". It completely did the $str!='' wrong.

In a debugger, we watched the value for $str and watched it step through the code. We clearly saw that while $str was empty (""), it executed the next line. Almost seems like a bug in the != operator but that obviously can't be the case.

This kind of baffled us.

To investigate, we var_dumped the value of $str, and this gave a very weird output:

 
   string(3) ""
 

An empty string, with a length of 3?

Eventually we noticed there were some weird control characters in there that translate to an empty string in output, but that do have a length. (Somehow this reminds me of black holes and dark matter).

We removed the char from the file (apparently, in a text editor, you could do 'delete' on the char, and although this didn't have a visible effect as it was an empty string in a text editor as well, it did work and we were able to process the file).

Lesson learned: not every empty string is an empty string. Control characters can have very weird effects. It can make a string look empty while it's not.

By the way: the people who created this file did so on a mac and uploaded it to a linux server. The weird chars were only at the beginning of the file, only on the first line. Does anybody know if there is some mac/linux/windows conversion that could cause these chars to appear?

PHP and Scalability

March 17th, 2008 by Ivo

Martin, one of our system architects, has written an article on our corporate blog about scalability in PHP.

He covers things like frontend generation (as opposed to request based caching), database replication, loosely coupled components to increase the scalability of the application, and he even mentions SOA (Service Oriented Architecture). We've recently had some good results with implementing SOA architectures in PHP. Traditionally SOA is associated mostly with Java, but with PHP5 it's very well doable.

Read his post here.