January 24th, 2013, 11:03 AM
Server with PHP?
I am new to PHP and I am asking this question mostly to see if its possible or not. I am trying to develop an Instant Messenger. I know I need a two applications;
- the server - accept new clients, return list of clients, forwards message from one client to the other.
- the client - connects to server, get list of other clients, sends messages to other clients.
For this design to work on the Internet I need to have the server application running on a machine with a static IP.
The problem is that I do not have a machine with a static IP...
... But I do have hosting which allows me to run PHP!
So I was thinking if I could write my server in PHP. I did a quick search on the Internet and I did find some examples. However I noticed that some examples are meant to run as programs (while a hosted PHP file would need to be triggered with a browser call I guess). I found an example which does work on my hosting (not all examples work) but connection times out after a minute or two and even trying to increase this timeout changes nothing.
So I was thinking; Is writing a server in PHP and host it possible? reasonable? Or just a really bad idea?
I would be interested to know why its a bad idea (if it is a bad idea) because it would help me learn.
January 24th, 2013, 11:08 AM
Your server will be a web server running something like php (or php, given you asked about php in a php forum) and a database (like mysql)
See something like this (the downloadable open source version): http://www.phpfreechat.net/
Last edited by Northie; January 24th, 2013 at 11:11 AM.
January 24th, 2013, 11:49 AM
Given that this is a chat client (with no real requirement for long term message storage) you should probably store the messages themselves in memcache, and only use a real database for long term credential storage.
PHP is not designed to be run as a daemon, sitting and listening for traffic.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.