I develop a chat-like application, my server should be written in PHP and client should be a passive one, just listening for data.
Right now i want to start with having two scripts:
send.php
and
server.php
send.php provides REST API to send message to another client via GET interface.
server.php should be a TCP server accepting connections from clients, for the sake of the sending data via sockets and is currently based on http://php.net/manual/en/sockets.examples.php, so right now clients only connect to him and he sends back some test string.
My problem is that i should somehow connect send.php and server.php so that when message was pushed via send.php server.php would actually send it.
How do i do that?
One option i guess is to store pushed messages in a server store and to check for new messages in server.php, but i fear it’s too resource-consuming.
Solution 1.
I solved my problem in a way i originally suggested, meaning i made server.php active so it checks for new information every second:
Realizing that making SELECT once in a second is not much of a work.
Solution 2.
Another approach i guess would look like this:
sends message to it.
This way messages would be sent to client immediately after they got ‘sent’ via REST interface by sender client, no checking loops would be running anywhere. You can even make your server.php (title becomes misleading in this solution btw) accept IPs via REST interface, so no additional TCP/UDP connection would be needed.
Solution 3.
Many clients (like iOS) this days have push notifications system and if client doesn’t get too many messages per day, the best way to do this is to deliver them is via push notifications. This way you wouldn’t have to have low-level network connections and REST interface would be enough.