Author: Nick Belhomme

Installing Ubuntu 8.10 BusyBox

Hello potential lost soul,

Developers everywhere in the world love using a linux variant.

I decided to use Ubuntu 8.10 Intrepid Ibex. But during install I had a lot of troubles getting it on my system.
I always got the initramfs and the busybox console. This made installing a real problem. As my system was new and I
did not know if it was a bios problem or some Ubuntu glitch. After reading and doing some trial and error with the tips on:

http://ubuntuforums.org/showthread.php?t=765195

I finally found the solution. I had to install with the extra options:

— all_generic_ide floppy=no irqpoll

This did the trick and 15 minutes later I was running Intrepid Ibex.

I hope  this post helps someone who is lost during the install and has the same problem I had. If this does not work I strongly suggest trying the link above as it has lots of other solutions posted.

Warm winter greetings from Belgium
Nick Belhomme

Ps. If you do not yet have a linux distribution you can use Ubuntu for free. Just download it or request a free cd at Ubuntu.

Ubuntu

Zend Framework Bug Hunting Day

Hello World,

I know it has been a while, no excuses.

But I have something important to tell the PHP community. Upcoming Saturday 08 November 2008 it is Bug hunting day. This BHD is  organized by phpBelgium and phpGG,  and sponsored by Zend, iBuildings and ServerGrove. If you would like to learn more about Zend Framework this is the day to do it. As this is the framework that will be worked on that day.

This makes it a great opportunity for beginners and experts in the field to sharpen their skills. Everybody has used a program that had bugs and those were very annoying. You hoped those would be fixed in the next release. Well we are going to open up Zend Framework and look at all the bugs that were committed to Zend and try to solve them. This means digging into the code and learning how everything works from the inside out. What a great opportunity!! We always need pratical uses to make studying pleasant and this is surely one of them. So take out your agenda and reserve this Saturday for a trip to Hotel de Goderie at Roosendaal between 11:00h and 17:00h. You would not only work on your favorite framework but also help the community.

It is free so please confirm your participation at Upcoming or at the website of phpBelgium or phpGG.

What to bring:

  • Good Humor
  • Motivation
  • A laptop
  • Money or a prepared lunch as this is not included in the day for people who have not registered. It has been provided by the Sponsors.
  • Another PHP Enthusiast

I will be joining this day, so I hope to see you then.

Happy Bughunting from Sunny Belgium,

Nick Belhomme
ServerGrove Webhosting    Zend The PHP Company     iBuildings The PHP Professionals

Zend PHP 5 Certification – Self Test

Today and from now on, on a regular basis, I am going to write about the ZCE Test.
http://www.zend.com/store/education/certification/self-test.php

I blog about it, because Zend has this great test online but doesn’t provide the answers. I know some of you will benefit greatly by me telling you the whys on every answer. But you should always take the test first!

Question 1
How can precisely one byte be read from a file, pointed by $fp?

A) fseek($fp, 1)
B) fgets($fp, 1)
C) fgetss($fp, 1)
D) fgetc($fp)
E) All of the above

The correct answer is fgetc($fp).
fgetcGets character from file pointer

But this definition on php.net is faulty. Beware fgetc() returns per byte as in the exam.  So if you use this function on a utf-8 formated file, you may encounter problems trying to display the character. As the ô character in the code below is split up over several lines.

Try the following code:

<?php
header('Content-Type: text/html; charset=utf-8');
$fp = fopen('somefile.txt', 'r');
if (!$fp) {
echo 'Could not open file somefile.txt';
}
while (false !== ($char = fgetc($fp))) {
echo "$char\n";
}
?>

and create in the same directory the following file: somefile.txt with the following content: “Bientôt!”

This will result in character encoding problems. Please do not forget to save your files in the utf-8 format. You have this ability in all good editors. If your editor does not support this, throw it away, set it on fire and forget about it. Check out Eclipse Zend, Zend IDE , phpED,  Komodo, …

Question 2
What object method specifies post-deserialization behavior for an object?

A) __sleep()
B) __wakeup()
C) __set_state()
D) __get()
E) __autoload()

The correct answer is __wakeup().

 The magic functions __sleep and __wakeup

__sleep
The standard PHP function serialize() checks if your class has a function with the magic name __sleep. If so, that function is being run prior to any serialization. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. If the method doesn’t return anything then NULL is serialized and E_NOTICE is issued.

The intended use of __sleep is to commit pending data or perform similar cleanup tasks. Also, the function is useful if you have very large objects which need not be saved completely.

__wakeup
Conversely, unserialize() checks for the presence of a function with the magic name __wakeup. If present, this function can reconstruct any resources that object may have.

The intended use of __wakeup is to reestablish any database connections that may have been lost during serialization and perform other reinitialization tasks.

Question 3
Where does the session extension store the session data by default?

A) SQLite Database
B) MySQL Database
C) Shared Memory
D) File System
E) Session Server

The correct answer is the File system. PHP saves session data at the end of every request by default in a file in the system’s temporary directory. This is a great solution as it will serve for most websites. But as websites tend to grow and receive more traffic. With more traffic your server gets slow and at a certain point you will want to add more servers, so the work load can be divided between them. At this point you might consider storing session data in a database. Luckily PHP offers a solution to overide the default. session_set_save_handler().If you want more information regarding this issue check out devshed.

Question 4
Which of the following data types cannot be directly manipulated by the client?

A) Cookie Data
B) Session Data
C) Remote IP Address
D) User Agent

The correct answer is Session Data. Everything else can easily be forged. As this information is all stored client side. And Session data is stored server side by your PHP script.

Question 5
What is the difference between isset() and other is_*() functions (is_alpha(), is_number(), etc.)?

A) isset() is a function call and is_*() are not function calls
B) is_*() are language constructs and isset() is not a language construct
C) isset() is a language construct and is_*() are not language constructs
D) is_*() return a value whereas isset() does not

Isset() is a language construct. These are built-into the language and, therefore, they behaves differently than functions. They have their own special rules. Check out the following code.

<?php
/* Variable functions, PHP supports the concept of variable functions. */
$fruit = array('banaan', 'apple');
$variableFunction = 'is_array';
var_dump($variableFunction($fruit));

/* But Variable functions won't work with language constructs such as echo(), print(), unset(), isset(), empty(), include(), require() and the like.*/
$variableFunction = 'isset';
var_dump($variableFunction($result));
?>

This code will result in a fatal error.

Question 6
What will be the value of $b after running the following code?

<?php
$a = array(‘c’, ‘b’, ‘a’);
$b = (array) $a;

A) TRUE
B) array(‘c’, ‘b’, ‘a’)
C) array(array(‘c’, ‘b’, ‘a’))
D) None of the above

The correct answer is array(‘c’,’b’,’a’) as (array) is a type conversion operator also known as a cast operator.

The casting operators allow you to cast variables to new types. Unlike the settype function, they return a value that is the value of the variable cast in the new type.
It is used simply as the data type you want to convert to enclosed in brackets and placed before an expression.

The casting operators are:

  • (int) or (integer) to cast to an integer
  • (float) or (real) to cast to a floating-point number
  • (string) to cast to a string
  • (bool) or (boolean) to cast to a boolean
  • (array) to cast to an array, in this case it is already an array, so no changes are being made to the array
  • (object) to cast to an object

Question 7
Which of the following function signatures is correct if you want to have classes automatically loaded?

A) function autoload($class_name)
B) function __autoload($class_name, $file)
C) function __autoload($class_name)
D) function _autoload($class_name)
E) function autoload($class_name, $file)

The correct answer is __autoload($class_name).

Question 8
What is the best way to run PHP 4 and PHP 5 side-by-side on the same Apache server?

A) Run one as an Apache module, the other as a CGI binary.
B) Run both as a CGI binary.
C) Just use .php4 for PHP 4, and .php for PHP 5.
D) Use .php for both but use different document roots.

You should run one as an Apache module, the other as a CGI binary.

Of course PHP as a CGI is not quite the same as an Apache module, performance / $_SERVER variable-wise.  You’ll get better performance with PHP setup as a module. Not only will you not have to deal with the CGI performance hit,  but if some of your scripts use basic http authentication, they do not work if you run PHP as a CGI. Naturaly there are ways around this, but that is what Google is for.

I hope you learned some stuff, and I’ll see you at the next Zend Certified Engineer 8 questions test.

Sunny greetings from Belgium
Nick Belhomme

Ps. Do not forget to bookmark: http://www.zend.com/store/education/certification/self-test.php and take the test as it will keep you sharp or prepare you to take the real ZCE  exam!

Let’s Connect!

Yesterday I was strolling the Fundays at Aarschot. The result was a new pair of pants and a great book written by Jan Vermeiren titled: “Let’s Connect!”. After relaxing with a drink or two in the sun it was ready to go home. I hanged the pair of pants in my closet and made my self comfortable on my couch. I picked up the book and started reading.

Hello there,  this is Nick Belhomme and today I am writing my 50 cents on “Let’s Connect!” written by Jan Vermeiren and published by Prenctice Hall.

Maybe you have heard about networking. Maybe you didn’t.

Answers.com has this to say about networking: “An extended group of people with similar interests or concerns who interact and remain in informal contact for mutual assistance or support.”

Please observe that no egoism or selling is involved in this definition. It has nothing to do with hard-selling. But everything about “mutual” assistance and or support. People can achieve great results, fantastic results, but we are only a men or a woman. Isn’t it obvious that you can not be the know all, be all?! It is only when people work together towards a bigger goal that big things can be achieved.

Doesn’t it make sense to contact people who maybe have the answer to your specific need or question? And in return you give them access to your resources.

Receiving is one part of networking, but the other part is even more important: Giving!

By giving without expecting something in return you build trust and a relationship. This is your most valuable resource. It creates opportunities and possibilities. Giving to your network makes you grow individually, spiritually and gives your career wing.

The book of Jan Vermeiren is all about networking. What it is, what it isn’t and how to successfully create or expand your (existing) network.  You will read about the traditional networking methods like events, seminars, letters etc. But also about the newer ones like LinkedIn, Ecademy, Xing and Ryze. It will also tell you how to do follow-ups and how to successfully introduce your networking base to each other.

The entire book has some very valuable information and is clearly written. Everybody that is already or would like to begin with networking should read this book.

It took me a couple of hours to read the book sitting on my couch, but it will save me months of doing things the “wrong” way. Because like everything in life there is a certain way you can do things to get them done more effectively. Reading this book is a good start.

Sunny greetings from Belgium
Nick Belhomme

Ps.  You can visit: http://www.letsconnect.be for free courses and a free light version of the book.