Archive

Archive for the ‘PHP’ Category

CodeIgniter’s log system issue

November 18th, 2009

First of all I have to admit that I love this framework. I will write more about this fantastic framework later.

But one issue I faced this morning and I was pulling my hair was its logging system.

I was editing the module which has few Ajax calls, some part was not working properly and it was absolutely because of the SQL. We have the main SQL commands being outputed in the CI log system as well. So I SSHed to server and open the log file in vi , searched for the desired point and was trying to figure out what’s the SQL problem.

At this point I got a message from a colleague asking whether our server is down or what ?

That was so confusing, some parts of the application were working and some parts were not. All the sections which were working like a Swiss watch few seconds ago. So what was wrong!
As usual everything was working properly on localhost.
I didn’t even give it a small chance that having the log file open for reading [I'm stressing this out : JUST FOR READING] could be the problem. CI couldn’t proceed with logging in the sections where we had used it. I just quit the vi editor and Voila. Coming back to life.

This is not a proper approach for log system, if it can not write to the log file it shouldn’t prevent the whole system from working. Or may be it should ! Depends on how logging is important for your system.

CodeIgniter, General, PHP , , ,

WAMP server: right-click and select your version

April 27th, 2009

Have you ever been in a situation that you need to install PHP5 to have one application which is spcifically written in PHP5 and you have also some legacy applications which are written in PHP4 and are not compatible with PHP5 but you want to have them both.

I used to hate all those software bundles installing Apache/MySQL/PHP for you easily. I prefered to have them separately installed by myself to have more control over it. But considering WAMP server with an amazing feature of having many versions of Apache/MySQL/PHP and just switch from one to another by right-clicking and selecting it, is awesome.

I’ll definitely consider it for my local machine. [First need to be done with my exam on Wednesday]

Apache, General, MySQL, PHP, Server , , , , ,

MySQL - group results by second/minute/hour

April 27th, 2009

This is a simple MySQL tip, but it helped me a lot.

We have a traffic table which monitors every single coming traffic to our applciation. I wanted to get the real values for how many requests I we have per Second / Minute / Hour and also what times of the the day are high traffic and what times are low traffic, to do some load-balancing on the application and server.

The query is very simple, just COUNT the number and do a GROUP BY and extract the minute/hour/…

Like :

SELECT tr_date_time,count(*) AS NUM FROM `traffic` WHERE DATE(`tr_date_time`) = ‘2009-04-25′ GROUP BY EXTRACT(HOUR_MINUTE FROM tr_date_time)

The script above extracts the number of hits per minute during the day.
Don’t forget that if you want to have the result by minutes, you have to add the hour as well to make it unique.

p.s: I hope your Date/Time/DateTime field is human friendly not Unix_timestamp, which will add some more extra calcuations on the result set.

General, PHP, SQL , ,

CodeIgniter xss_clean semicolon addings

April 17th, 2009

When you use that perfect xss_clean function from CodeIgniter’s library to make your content more robust, sometimes you may face a strange content being updated in DB having “;” after “&” or before “=” .

That “;” is added by xss_clean, to make the link more robust, but if in your case it will add some malfunctioning in your system you’d better use something else in your validations like “htmlentities” :

$rules['link']                =     “required|trim|htmlentities”;

For more information regarding that you can refer to CI forums. [thread1] [thread2]

CodeIgniter, General, PHP , ,

IDEs for PHP development

March 14th, 2009

It’s been a long time that I used different IDEs for PHP development. I started with DreamWeaver 4.0 and grew up with the next versions.
Still I believe that none of the IDEs is as handy and easy to use as DreamWeaver, but unfortunately it didn’t update itself with developers’ needs. Integration with code repositories and code navigation are the basic needs for today’s development.

Well it has some features to support SVN in the CS4 version, but I prefer not to mention it because it has lots of flaws. And code navigation and class/method listing is not there, there are some extensions to give you the same concept but they’re not that much useful.

Once in a while I tried the other IDEs. I tried ActiveState Komodo long time ago but it didn’t work out for me at all, lots of problems with searching and searching through the folders and serious problems with unicode. They might have debugged all those things but that experience was enough for me.

NotePad++ is a great editor but you can not mention it as an IDE.

When PDT came out I was excited about it but the more I worked with that the more I disliked it. Very slow, lots of bugs and suddenly freezes and lack of so many features.

I also tried Aptana Studio for a while, but the same thing as PDT,, pretty slow and suddenly freezes. Which I eventually understood that it’s because of Eclipse.
Oh God! Eclipse ! It has a wonderful plugin-based software architecture, amazing integration and lots of plugins, but it just have 2 flaws :

  1. VERY slow
  2. Suddenly freezes without any reason

I don’t know why they love it so much at schools.

I moved to PHPed and I still use it for a some projects. One of the most important things that I really like from PHPed is the DB client, which you can Drag/Drop DB fields instantly from the IDE without considering any typo or need to go to another application to copy/paste them. The other thing that I really like is Shell-Menu access, it means you can have the menu which you have my right-clicking on the item in windows-explorer, so it doesn’t matter if it doesn’t support SVN or not [which it does] you can easily do whatever you want by accessing the shell-menu.
But on the other hand it has it’s own strangnesses, the most important of all shortcut keys are totally different [ctrl+Y does a line delete instead of Redo and so on...]
I still use it for some of my old projects though.

I’m not a Java fan at all, and I only use it when I’m completely obligated to use it at school [still wondering why do they love Java that much! ] . But for a school project I had to download Java and install it so I can study, and I was really shocked when I found that Eclipse has not been mentioned anywhere in Sun MiscroSystem’s website at all. But they suggest NetBeans for Java Development, I downloaded the package containing Netbeans and JDK, I studied but you know, when you want to study you do everything else rather than studying :P it was exactly the case for me and I ended of finding an official plugin developed by NetBeans team for PHP development.

I can say that’s IT… That’s what a developer exactly needs for PHP development, it’s fast and smart. That is really it… Free and supports all the features you need. Give it a try and you’ll definitely like it.

As a MacroMedia/Adobe fan I’m still looking forward for them to provide a great IDE for PHP developemnt, but they should hurry.  They’re loosing so many of their users for the lack of the features I mentioned above.

While we’re looking forward for Adobe, let’s take a look at NetBeans and enjoy it.

IDE, PHP , , , ,