diff -r 7a1573676cc4 -r 2adca0f363fd greyhound.php --- a/greyhound.php Mon Mar 31 07:40:30 2008 -0400 +++ b/greyhound.php Wed Apr 02 00:23:51 2008 -0400 @@ -25,9 +25,22 @@ pcntl_signal(SIGINT, 'sigterm'); } +// +// CONFIGURATION +// + +// Listen on all interfaces. If this is false, it will only listen on +// 127.0.0.1 (the loopback interface) $public = true; +// Allow control of playback. By default this is turned on but if you +// set this to false, it will only display the playlist. $allowcontrol = true; +// The default theme. This should be a name of a directory in ./themes. $theme = 'funkymonkey'; +// Allow forking when an HTTP request is received. This has advantages +// and disadvantages. If this experimental option is enabled, it will +// result in faster responses and load times but more memory usage. +$allow_fork = true; @ini_set('display_errors', 'on'); @@ -42,7 +55,7 @@ // start up... -status('Starting WebControl v0.1-hg'); +status('Starting Greyhound Web Control v0.1-hg'); status('loading files'); require('webserver.php'); @@ -99,7 +112,28 @@ $httpd->add_handler('scripts', 'dir', GREY_ROOT . '/scripts'); $httpd->add_handler('favicon.ico', 'file', GREY_ROOT . '/amarok_icon.ico'); $httpd->add_handler('apple-touch-icon.png', 'file', GREY_ROOT . '/apple-touch-icon.png'); + // load all themes if forking is enabled + // Themes are loaded when the playlist is requested. This is fine for + // single-threaded operation, but if the playlist handler is only loaded + // in a child process, we need to preload all themes into the parent before + // children can respond to theme resource requests. + if ( $allow_fork ) + { + status('Preloading themes'); + + $dh = @opendir(GREY_ROOT . '/themes'); + if ( !$dh ) + burnout('Could not open themes directory'); + while ( $dir = @readdir($dh) ) + { + if ( $dir == '.' || $dir == '..' ) + continue; + if ( is_dir( GREY_ROOT . "/themes/$dir" ) ) + load_theme($dir); + } + } $httpd->allow_dir_list = true; + $httpd->allow_fork = ( $allow_fork ) ? true : false; $httpd->default_document = 'index'; status("Entering main server loop - ^C to interrupt, listening on port $port"); @@ -109,4 +143,3 @@ { burnout("Exception caught while running webserver:\n$e"); } -