Hi there.
I am developing an application in which I am using AJAX and PHP. Lets say from my initial.php files I am making request via AJAX to ajaxResponse.php file where I execute some code and interact with MySQL .Since I am handling with dtabase I am using my written Db class and on the top of my ajaxResponse.php I have to write

    $db=new Db();

in order to use the methods of the class. I can send request to that files 1000 and more times (since I am building a livechat) and in all times it will do that require_once and $db=... . Do you think thats the best solution ? What disadvantages it has ? And what other methods you suggest to sort that out So i'll require only once or maybe anything else that you will recommend .

Thank you in advance for your efforts !!!

I don't think there is much else you can do, except for maybe caching your results somehow (if possible).

This is why ajax and php are ill suited for a real-time chat solution. Because it has to make a new request every n seconds which means you're hitting the system fresh every time since php does not really maintain state between requests.

You would really want to look at Comet

Or, implement some form of long-polling

My application is not gonna appear online since its an experiment task so no worries about ajax and php not well suitness. And thanks for your replies. By the way I think I found a solution to my problem : SINGLETONE PATTERN