/    Sign up×
Community /Pin to ProfileBookmark

PHP Chat with no SetInterval function

Basically i want to know if there is a way to send data from server to client when on server something happens (for example mysql insertion)..
The script must run to all sessions.
I don’t want to call a javascript function every X min to check if data has changed.

Another one question:I want to write a mysql trigger to run a php script.How i will do that?

Thanks in advance!!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@el07694authorApr 27.2011 — no reply yet?
Copy linkTweet thisAlerts:
@NogDogApr 27.2011 — In normal use, PHP web apps are "pull only", you cannot push data to the browser from your PHP script on the server unless the browser has asked for it via a HTTP request. This is one reason that most chat applications use something like a Flash or Java applet on the client side that can "listen" for data from the chat server. Therefore, I suspect (but don't claim to know for sure) that if you want to do what you are describing, you'll either need to use some sort of applet on the client side and possibly some sort of socket programming on the PHP side (?), or else bite the bullet and go with the JavaScript periodic HTTP request technique. But like I said, I'm by no means 100% sure about this.

As far as MySQL triggers, a bit of Googling would seem to suggest that you cannot directly call an external script from a trigger. It seems the most common approach is to have the trigger use the SQL "INTO OUTFILE" command to write pertinent data to a file on the server, then have a cron job (or a daemon process) look for such a file and if found process it through whatever script (including a command line PHP script) you want.
Copy linkTweet thisAlerts:
@ryanlundApr 27.2011 — I may be incorrect but didn't javascript recently add the ability to connect to sockets (when html5 came around)? In that way you could program a php chat server which accepts a socket connection and pushes the chat data out?

I mean, dont quote me on this as its not something ive delved into myself...but a quick google search may come up with some interesting results.
Copy linkTweet thisAlerts:
@aroravineetApr 27.2011 — Javascript (AJAX) is the solution dear, but if you still do not want that, its a lil tough but the Solution is Socket Programming...

Study Socket Programming in PHP....
×

Success!

Help @el07694 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...