PHP Quebec 2008

I will attend the PHP Quebec conference in March http://conf.phpquebec.com/

see you there!

PHP and deamon in hight availability solution

I found a good article on PHP and daemon processes( http://www.php-mag.net/magphpde/magphpde_article/psecom,id,484,nodeid,21.html). There’s not a lot of documentation on how to work in PHP in shell mode. I wrote previous articles on this. PHP is taking more place in the enterprise, being able to write back-end process is a key to open doors.

When you run daemon application one of the biggest challenge is to monitor the processes you’re spawning. I don’t have a lot of history working with daemon and back-end so I read a lot about it.

We are about to switch our hosting solution for a high availability solution.  The application I wrote a few months as to be tweak. The application will be running on the two servers. One will be in Sleep monde and the other one will be in active mode. The main problem is to switch data over each PHP processes on the same server and the do the same over the two servers. The application also requires acting on certain condition. If the data feed is cut the server in sleep mode as to take over.

I will break my application in part and show you some my work in the next post.

  

Zend PHP conf

I just completed my inscription to the Zend/PHP conference. It will be firsth attemp to that conference.  I can’t wait until October.

Why a do I need a PHP certification

I took a look at the requirements for the PHP5 certification test. My good!!! I’m working with PHP for over 4 year and I’m not sure if could do it. But why in the first place you want to go take this exam. So far I see no reason. Except I just put a ++ after your name on a CV pile. Since there’s not a lot of people around the world having this certification the chance that you have to run against one of them are low. Ok I would leave some area of the globe a side but I think it’s true in my Town and State (Montreal Quebec Canada).  Only 40 are in the same state of me and 15 in the same town. Does the test will make you a better programmer? Not sure!

Page Cannot be displayed!

Over the past months, we have been experiencing problems with our Website. User get on a random base a page cannot be display trying accessing our web site. On Firefox we get prompt to download the page. If you do it you will get an empty file. It is important to note that we have been unable to reproduce the problem outside our offices. From home or from various locations it is really hard to reproduce the problem.

I will try to describe the problem accurately and present our solution to it.

Symptom:
The user gets a “cannot be displayed page” message. This sometimes happen on the first load or after browsing for a while. This situation only occurs when the user is visiting.html or .php pages. Often, these pages contain PHP sessions and Java Script.

How to Replicate the Problem.
Force refresh (ctrl+F5) several times one of the pages. After a while you get stuck. If you try other pages within our site you won’t be able to access them.

Apache and PHP logs alone were not useful. I’ll discuss these logs later on. At first, we looked at the httpd.conf and php.ini servers configuration, which are standard with a normal Apache 1 and PHP4 configuration. This is noting out of the ordinary.

Then, we used “sniffer” to try to find out what is triggering the error in the logs. We found out that, sometimes, the browser keeps the connection alive to some stuff but never do anything.
On the Server, we noticed the same behaviour. It seems that Apache opens a socket to write but gets stuck at one point.  When Apache does this, it is locking your session. Further investigations revealed that the browser tries to send a reset but this reset is lost in the process.
Why does a browser need to send a reset? In the sniffer log we found 302 http codes on images. Last year, we completely redesigned our Website and we cleaned the image directory, which contained over 1 gig of images. All the images that at the time were presumed unused have been downloaded locally and deleted from our server. We also have a Custom Error Page that uses a PHP header location to redirect users on our home page if the page can’t be found. This is the explaination for the 302 http codes on the images. 

If the following five elements are in your configuration, you might encounter the same problem we did.
- Custom error page that redirects on another page automatically
- Missing images on your Web server
- Session
- JavaScript images loader
How We Fixed the Problem
We used the error log to focus on images (.jpg and .gif) that couldn’t be found. Then, we created a batch command that took each line and created (using the touch command) empty file having the same name. This solution is temporary. You need either to fix your script or to re-upload the images.

How to not Parse a directory

My application has to look in a specific directory to know if a new file has been added. I still have no clue. How to do it in PHP without parsing the entire directory?

Do it simple

Some time you want to do simple stuff but there’s no way to accomplish that.

I am trying to check if my file has a specific marker. If yes delete it because this file will be uploaded directly to my DB.

I came out with this code:

$fileRess = fopen($fileFullPath,"a+");
$pos = -10;
fseek($fileRess, $pos, SEEK_END);
$content = fgets($fileRess);
  if($this->marker != $content){
  echo "Marker is not present in the file"."\n";
  fclose($fileRess);
  return false;
  }
fseek($fileRess, $pos, SEEK_END);
ftruncate($fileRess,$size-10);
fclose($fileRess);

Posted in PHP, PHP4, PHP5. 1 Comment »
Follow

Get every new post delivered to your Inbox.