PHP and loading code dynamically

Discussion in 'OT Technology' started by Astro, Nov 1, 2003.

  1. Astro

    Astro Code Monkey

    Mar 18, 2000
    Likes Received:
    Cleveland Ohio
    Off and on I've been thinking about this problem: I have a PHP script which sets up a socket server. The socket server works and does its job nicely, but I'd like to add functionality to the server (think of it as adding menu options - I wish to add code to handle the new menu options). But I really don't want to have to start and stop the script. So I wish to dynamically load code.

    By default, the eval() trick would work. It gets a little messy trying to escape everything just right.

    I've thought about using include and require. The trick is I'm not sure if they do any caching. I don't think either one does. The ones I'd have to stay away from would be include_once() and require_once() (these won't work).

    Now to make things a little more interesting, I really only want the code to be reloaded when the code gets updated (versus reloading it every interation of the "server duties" loop). I'm thinking file dates and looking for a change in date, but I'm not sure I want PHP hitting up the file all the time even though the file hasn't been updated. Hmm...

Share This Page