Re: include

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tim Streater <tim@xxxxxxxxxxxxxxxx> wrote:

> At the moment I'm using an instance of apache to run PHP scripts, as
> and when required via AJAX. Having got some understanding of web
> sockets, I'm minded to look at having a small server to execute these
> functions as required. The scripts, some 50 or so, are only about
> 300kbytes of source code, which seems small enough that it could all
> be loaded with include, as in:
 
> 
> <?php
> $fn = 'wiggy.php';
> include $fn;
> ?>
> 
> This appears to work although I couldn't see it documented.

I'm really not sure what you're looking for here -- that is pretty
standard php practice to load php files with include -- what were you
expecting here?

While it's certainly possible to rig up something using sockets, I don't
think that's how AJAX works, and you'd need a JS library that did.

As an alternative, can you set up a lightweight web server like lighttpd
and fastcgi on your host machine? This should give you the speed and
flexibility without incurring the overhead of loading everything into
mod_php under apache. The alternate server would listen on a different
port and dispatch fastcgi to deal with the php scripts.

As well, you could run fastcgi from apache to dispatch the smaller
scripts if you didn't want another web server running, although in
practice this hasn't proven to be an issue for me.

> I'd also like to be able to replace a module without restarting the
> server. I couldn't see a way to drop an included file, do I therefore
> take it that there is none? Failing that, is there a good way to
> dynamically replace parts of a PHP program, possibly using runkit?
 

Generally, you should only really need to dynamically replace parts of a
long-running program if you don't want to restart it. However, php
scripts are not long-running programs in general, unlike the apache
server itself, for example, and certainly if the php scripts are running
under apache, they will be time- and space-limited by whatever is set in
the php.ini file. If these little scripts are merely responding to AJAX
requests, they should be really short-lived.

OTOH, if you do have a need to replace an include file, you can include
it again unless you use something like "include_once" or
"require_once". Otherwise, the bare "include" and "require" commands
will merrily go ahead and re-include the file. What you really need to
watch out for is dealing with initialization of variables in the include
file, and if what you're including are classes that the previous version
has objects out for, what happens then is going to be pretty strange.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux