I wrote a PHP chat system similar to gChat which simply uses constant ajax calls to update the chat. This system is fine for a few users, but with potentially thousands of users, it is much too hard on the server. I've been considering taking the 'Comet' route, but have heard that PHP can't handle Comet very well. What would be the best language/API to perform real-time chat for a large user-base?
I was thinking of implementing real time chat using a PHP backend, but I ran across this comment on a site discussing comet:
My understanding is that PHP is a terrible language for Comet, because Comet requires you to keep a persistent connection open to eac browser client. Using mod_php this means tying up an Apache child full-time for each client which doesnâ€™t scale at all. The people know doing Comet stuff are mostly using Twisted Python which is designed to handle hundreds or thousands of simultaneous connections.
I need to create a chat similar to facebook chat. I am thinking to use ajax polling ( to send request every 2-3 seconds ). Is this a good approach ? Or I need to use other server side languages like erlang and server-comet ?
If I have entries in a mysql db and I want to display the most recent entry on a web page in real time, how would I go about this? Would I have to write a script that queries the database every couple of seconds? Or is there a way to get the database to communicate with a script so that it only gets queried when there is a new entry?
I am just thinking about the best way of not overusing the server by checking every 1-2 seconds. Something a bit like a forum "users currently online are: etc.." but up to date within a few seconds.
EDIT: I'm not sure if this would work but sometimes you get those annoying pop-ups that tell you what city/suburb you're in (usually for dating sites) - could we somehow extrapolate from that data what the time is? Is this data based on a reverse IP lookup??
I do have the countdown script (see link below) to display the time between current time and the date given in real-time. However, I want to achieve to display the time difference between a given start and end time. Right now, it calculates from the current server time to the end time. I want to be able to set up my own start time and end time. Here is what I have: [URL]
I'm a relative PHP newbie, so I apologize if this is a simple question.
Anyway, here's my problem. I'm using a PHP script to pre-render a bunchload of insert files for an HTML page. Right now there's about 1,600, but that number could get much, much higher when the site goes live.
I'll only need to re-render the whole batch once or twice a year (if that) but it's still something I'd like to be able to do in case I have to move the site to a different server, or there's a hard drive crash or etc.
Basically what the script does is grab a whole bunch of information from a database and write the insert file. It does this for every single one.
The problem of course, is that PHP by default does all this server-side, and then sends it to the browser. Because this process takes like ten or twenty minutes to do, the browser times out long before it's finished.
Is there a way to get progressive output with PHP? Or do I need to re-do this in another language like Perl?
I am making a web-based chat but to get the msg from the database i need to refresh the page and that will make load and extra bandwidth on the server so i want to make the query in real time ( only the new msg to be received without refresh the whole page ), Any one in here knows how to get data from sql database without having to refresh page.
I am currently displaying date/time on my webpage using the date function PHP provides. However, using this function, the date/time will only be updated when reloading the page. I have the date/time updated every second instead.
I'm trying to figure out how to display output (and read input) in real time in a process launched by PHP on the command line. There seem to be many alternatives: shell(), exec(), system(), popen(), proc_open()
and it is not completely clear to me what are the differences. All I need is to execute a process, display its output on the same terminal where the PHP script is invoked, maybe read input and finally return to the PHP script flow when the process exits. Among the options I listed proc_open() is probably able to do this, but it seems overkill, as all I want to do is to give control to an external process and wait for it to finish.
There are some questions which seem related, but as far as I can see they are actually about sending the process in background (which I do not want) or displaying the output in a browser (which is not my case, everything is in a terminal).
i have a big loop, and rather then waiting until its done for me too see what happened, every time it runs, how can i get the browser to echo the result, and proceed to keep running the loop.
basically this loop takes a long time to finish, and i had to set my max runtime past 30 seconds. i guess incorporating a refresh of some sort like this would eliminate the need for the time extension too?
i have a script that i wrote for my clan/guild/linkshell in this online game i play that keeps track of members, the points they receive from events, items etc. in the admin panel of the script where you can update peoples points i want to know if i can add a button or something similar that if you push it updates the points which is currently in another text box in the same form in real time.
I'm sorry if i'm not being clear, what i'm trying to do it make it quicker to update a members points because usually after each event they receive either 10 or 20 so i want to add a button where if you push it then it will put 10 or 20 in the 'add' box in real time. right now when you edit a member it shows their current points in a text box and under that two text boxes, one if you want to add points and another if you want to subtract points.
if this isnt possible then i assume that i'd have to make it update the points in the box and keep all the values from before and just reload the page with the new value inside the box. wow, i'm sorry if i'm not very clear, please ask questions if you dont understand what i'm trying to say.
What would be a proper solution for automated decision making in a PHP script, like a game? That is, without an external application, or any human input. For example, any random event that happens when the player is away from the game. How would one go about implementing that?
Is it possible to upload a file to the FTP server using PHP script while the same script is downloading the meant file from somewhere else? So at the time script is downloading it should upload the file in real-time.
Getting the time from a Wordpress post (the field being post_date_gmt stored in DATETIME), how can I convert that information (e.g 2011-03-23 20:28:26) to an actual, maleable date in PHP? (like Thursday, March 23rd, 2011)
I want to Make a Script which give result realtime. In My Script it have 3 steps. 1st step was to grab all links from a webpage .(i use pregmatch_all function coz all links i need are started with same domain [URL]... and grab from [URL]... ) 2nd step i have to grab direct link from all links (like [URL]...) 3rd step Upload that file to and third party site and get the upload link from there . lastly i added a function named which get the page ranges (like '1|5' ) so script upload all links from [URL]... I have done the scipt it was alo running ok but it shows result after all completed but i want a realtime result like script have grabed one link and do all steps with it and show that reult link on browser and then so on i mean a realtime solution. How can i do that i used for loop but no real time result.
I am building a website in which the user can select what list items they see in their navigation menu, my idea is to store the menu items that the user selects in a cookie as this will stop the need for the user to be registered member on the website, is it possible to store realtime data in a cookie and how would I do this? For more information the navigation options are built from a mysql result, the then clicks a link and that link is added to a different list, if they click it again it is deleted, I need to add/remove these items from the cookie as the user add/removes it from there list.
This question evolves around the concept of how we can add <a name="id here"></a>'s on a web page to allow a visitor to skip to sections of the page without having to scroll down a lot. I'm thinking about how I could achieve this in PHP. A web page would have various <a name="id here"></a> scattered throughout its length (the longer the page the more there would be) and PHP would simply go from top to bottom and add a numeric value for each one.
Any ideas how you would tackle this one? The ID's could be 0, 1, 2, 3 etc. so the $i = $i++ is fine but it's getting that to paste itself automatically inside of each <a name="id here">. I guess I could just put $i = $i++ after each section then <a name="$i"> however somehow I'm not convinced that's the professional way to go about it.
I'm thinking along the lines of having a function which spits out an ID then preserving the value for the next time it's called, in which case it will simply +1 to the preserved value. The preserved value then is deleted once the function is called the last time on that page so if the page is refreshed it would start from 0 or 1 again. As it's only going to be a few lines of code I don't think there's any concern for server CPU time in this case given it will generate the ID's on each page refresh.
I was wondering if anyone had any good starting points for making a web based app that had Collaborative real-time editing.
Is it possible to play the video (mp4) in real time using some flash player? What I mean by in real-time is that player would receive data on the fly, not from alredy saved file but e.g. php script (which sends appropriate content-type header) THAT IS DOWNLOADING AND 'ECHO-ing' THE FILE AT THE TIME PLAYER PLAYS IT - like e.g. some kind of live stream.
how does facebook achieve their 'real time' effect? For instance...it shows 4 New Posts or your notifications as soon as they happen without having to refresh the page. I want to implement this on my website for personal messages and other things. I just have NO idea where to even start
One solution could be using session variables. I can make a script that looks for this variable, if it doesn't exist means that the user is entering the site. Then I set this variable with current time. The script it's in each page, and it will be reading this variable via AJAX each x seconds and I'll know when the user is in my site since two minutes.
I don't know if it's right or not (I've not implemented yet), but I'm not pretty sure if session is the best way. If the user leaves the page but has other navigator windows opened, the session doesn't expire, and if he enters the site again, the counter will not be reset.
So, two questions:
Is there a better method to have more control on the real entering and exiting? If not, is my above approach right?