php chat client - php

i need to create a chat application in php+js+ajax which need to be integrated to a site, where am stuck is to create a chat window , that need to be constant while going through different pages in the site . if any one can suggest a better way i will be grateful, thanks in advance

As for the actual chat application...
Using some kind of technology to push data from the server -> your users is the best way to achieve a real-time chat application.
I would highly recommend checking out APE (Ajax Push Engine).
It takes care of the server-side stuff and allows you to seamlessly transfer data from the server -> client.

As far as the chat window staying when you change pages, I can think of three options:
Put the chat in a separate frame and only change the main frame when going to a new page.
Change the page content with AJAX instead of making a full page reload.
Assuming the chat messages are being stored on the server, simply repopulate the chat with the most recent messages after the new page loads.

There are plenty of tutorials available, try one of these three that came up first from a Google search for "php chat tutorial":
http://www.tutorialized.com/tutorials/PHP/Chat-Systems/1
http://code.jenseng.com/jenChat/
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=9

Related

How does the Facebook chat load new messages without you refreshing the page?

I'm trying to push my skills with PHP and SQL that I've recently learnt at college; I'm making a website that I can chat with some friends on. I know how i'll do everything ( log on, save messages & display messages ) but I'm unsure of how to make the messages constantly load instead of having to reload the page like on Facebook.
If I was to use this: while($sqlRow = mysqli_fetch_array($sqlResult)){
Would that keep loading messages as they're added to a table for holding messages?
I think the easiest way to implement this is to use web sockets: think of a web socket as a two-way communication channel that is always open between your client and your server. Even though your client is done loading the page, your server can still send messages to it through this open channel, at any time.
I have never used web sockets with PHP (only with javascript and node.js), so I can't really help you with how to actually implement this system. However I found this article that may help you: http://www.phpbuilder.com/articles/application-architecture/optimization/creating-real-time-applications-with-php-and-websockets.html
Let me know if that helps.

PHP web scraping - return content after javascript loads

I'm creating an applition that crawls a website, logs in to an account and accesses the user's travel information.
Once I login and go to the page that displays a list of travel cards, I need to click on the View journey history link.
So here is the problem: the View journey history link only appears on the page once a Javascript script loads (I'm not too sure which). When I run my crawling script and I print this page, I can view the View journey history link (because it loads the javascript on the browser). However, when I try to crawl this page to find this link, it doesn't find it. My assumption is that this PHP library does not have a facility to run javascript (a browser-side language) on the backend.
How can I return the page html AFTER all javascript scripts have loaded and processed?
I'm using Goutte to crawl. This library uses Symfony BrowserKit which is supposed to simulate the behavior of a web browser, it would be good to know if it has a facility to process javascript before returning the html.
I'm open to any type of solution, meaning the use of different libraries, or even a different programming language.
Thanks in advance.
I've custom curl package for Laravel.
After login, you need to monitor the requests closely[use Google Chrome's Network tab.].
there are couple of scenarios.
1) website is making ajax request to some other url. You need to catch that url and send ajax request to that url to get data.
2) website is using javascript to render page data. In this case data will be already embedded in page source[js code]. You need to use regex to extract data from the page.
I only can this much of help without analysing calls, page source.
BrowserKit and PHP alone don't have the ability to execute JavaScript. There's a few options out there though; you could use something like Selenium and WebDriver or PhatomJS and automate things using something like Codeception (which is actually a testing library but could be used for scraping):
http://codeception.com/docs/modules/WebDriver
The disadvantage here is that this approach is quite slow and may not be compatible with whatever hardware you're running your scripts on (i.e. a web server with no GUI or browser).
Another approach would be to use ChromeDriver which is a bit quicker and more lightweight than Selenium and WebDriver. You can then automate all of this using Laravel Dusk (again, another testing library but nicely suited for this sort of thing):
https://laravel.com/docs/master/dusk

How to Build a realtime multiplayer game using action script (flash) and php backend

I wanted to build a real time multi player game using flash (action script 3) as front end and use php as back end language and mysql database. There are lot of posts and tutorials online, but nowhere I found an article which would suffice my requirement.
I thought of using smartfox server. But lately they are not supporting php backend technology. Here is the answer by their technical person.
http://www.smartfoxserver.com/forums/viewtopic.php?f=18&t=15791
This seemed to be a useful post, but it didn't give me complete information as to handle the game play with php back end.
http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/
Do we have to use web sockets in front end. And how to handle the user's delay on the website. Also I am supposed to use Facebook Login to get more users on the game.
My game should have multiplayer feature just like this one on facebook.
https://apps.facebook.com/livepool/
Can someone suggest me on this please.

how to implement facebook like notification?

I am trying to implement a Facebook-like live notifications system to notify users whenever someone adds them as friend, like their post or posts replies to their comments.
All the database and PHP part is done, but I can't figure out how to implement it like Facebook has.
Whenever someone likes/comments on your post in Facebook the light blue box appears at the bottom left corner of the screen. This happens as soon as someone hits like button or posts comment in Facebook. I would like to know what I should do to implement this.
Using YUI or any JavaScript framework I can query a database table after n seconds to check for notifications. This method is too heavy.
I was wondering if there is any server side mod or scripting can be done so that whenever there is new notification entry in my database table the server will tell that particular client. That way unnecessary request calls from client to server will be avoided completely and system can work efficiently for website with more than 50,000 users online at a time.
How can I achieve this?
You should look into COMET techniques, such as forever frame (tutorial) and long polling. That allows you to have a form of a server->client push communication.
I am really surprised nobody has mentioned PubNub and Pusher
These two (competitors) are building infrastructure which allows for realtime notifications, just like Facebook.
Facebook notification
You basically set a request up, like callng the service that asks your server/db for the notifications of that user. You may do a while loop that retries if theres no notification (maybe Thread.Sleep in between searches). Your js request will timeout, then you can call the function again in timeout. This means long polling afaik
The only way to do it is to have some sort of mechanism (e.g. Javascript) to repeatedly poll the server for updates. Doing server pushes to web browsers isn't possible.

Gears and Mysql sync

I am making an offline website that needs to sync every night with a server. Our employees work outside and sometimes underground and need to access the site for its database. But once home they must send us their findings.
The first time they connect, I check with google gears if they have the sqlite database and if not I run a script to insert it. Once they have it, I sync their next appointments to their local database.
When they are done, the next day, they connect to send us every thing and to download their new appointments.
For now i was able to create the sqllite database and insert new values inside thanks to google gears. But i haven t found a way to read the database with php to sync it with our online database.
To go from online to off, with PHP I can write an array in a hidden field and then read that field with JavaScript. But in the other way i was wondering if there was on other way then creating a form with DOM and submitting it in JavaScript to read the values with PHP?
I need to sync a Lot of values, do you know if there is an easier way?
Thanks for your help
I have found vortex, a powerfull script for gear that helps sync everything from files to data. It will definitely help me.
Here is the link to the developer's blog. The download link is in there.
I will come back when the website works to help the interested.
You should use Ajax for posting your new data to the PHP server.
You could use jquery (or any other framework), their lootle of resources how to post data to php on the web.
Your webpage could have a button hidden when offline, this button would enable user to start a synchronization.
Here a tutorial from PHP and jquery!

Categories