#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2004
    Posts
    597
    Rep Power
    140

    Server with PHP?


    Hello,

    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;

    1. the server - accept new clients, return list of clients, forwards message from one client to the other.
    2. 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.
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    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)

    This serves web pages with html and javascript to the client's web browser - this forms the client app.

    See something like this (the downloadable open source version): http://www.phpfreechat.net/
    Last edited by Northie; January 24th, 2013 at 11:11 AM.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    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.

IMN logo majestic logo threadwatch logo seochat tools logo