greyhound.php
changeset 34 3b817b961984
parent 33 3b4aef1efff6
parent 31 48004643a8a5
child 36 70ef461bbffa
equal deleted inserted replaced
33:3b4aef1efff6 34:3b817b961984
    35 $public = true;
    35 $public = true;
    36 // Allow control of playback. By default this is turned on but if you
    36 // Allow control of playback. By default this is turned on but if you
    37 // set this to false, it will only display the playlist.
    37 // set this to false, it will only display the playlist.
    38 $allowcontrol = true;
    38 $allowcontrol = true;
    39 // The default theme. This should be a name of a directory in ./themes.
    39 // The default theme. This should be a name of a directory in ./themes.
    40 $theme = 'funkymonkey';
    40 $theme = 'grey';
    41 // Allow forking when an HTTP request is received. This has advantages
    41 // Allow forking when an HTTP request is received. This has advantages
    42 // and disadvantages. If this experimental option is enabled, it will
    42 // and disadvantages. If this experimental option is enabled, it will
    43 // result in faster responses and load times but more memory usage.
    43 // result in faster responses and load times but more memory usage.
    44 $allow_fork = true;
    44 $allow_fork = true;
    45 // set to true to enable authentication
    45 // set to true to enable authentication
    62 define('GREY_ROOT', dirname(__FILE__));
    62 define('GREY_ROOT', dirname(__FILE__));
    63 
    63 
    64 // create directories
    64 // create directories
    65 @mkdir('./compiled');
    65 @mkdir('./compiled');
    66 
    66 
       
    67 // what kind of terminal do we have?
       
    68 $use_colors = ( @in_array(@$_SERVER['TERM'], array('linux', 'xterm', 'vt100')) ) ? true : false;
       
    69 
    67 // start up...
    70 // start up...
    68 
    71 
    69 status('Starting Greyhound Web Control v0.1a3');
    72 status('Starting Greyhound Web Control v0.1a3');
    70 status('loading files');
    73 status('loading files');
    71 
    74 
    83   global $httpd;
    86   global $httpd;
    84   status("Caught SIGTERM, cleaning up.");
    87   status("Caught SIGTERM, cleaning up.");
    85   exit(0);
    88   exit(0);
    86 }
    89 }
    87 
    90 
       
    91 status('doing PHP capabilities check');
       
    92 if ( !function_exists('pcntl_signal') )
       
    93 {
       
    94   warning('System does not support POSIX functions. Termination signals will result in unclean shutdown.');
       
    95 }
       
    96 
       
    97 if ( !function_exists('simplexml_load_file') )
       
    98 {
       
    99   warning('Can\'t find support for SimpleXML, which is needed to parse the Amarok playlist file.');
       
   100   burnout('SimpleXML required to continue. You may have an outdated version of PHP; most versions of PHP 5 have SimpleXML built-in. Check your distribution\'s documentation to find out how to enable PHP\'s SimpleXML support.');
       
   101 }
       
   102 
    88 status('initializing playlist');
   103 status('initializing playlist');
    89 
   104 
    90 // init playlist object
   105 // init playlist object
    91 $playlist = array();
   106 $playlist = array();
    92 $amarok_home = false;
   107 $amarok_home = false;
    97 $port = 7447;
   112 $port = 7447;
    98 
   113 
    99 try
   114 try
   100 {
   115 {
   101   status('starting PhpHttpd');
   116   status('starting PhpHttpd');
   102   status('doing PHP capabilities check');
       
   103   if ( !function_exists('pcntl_signal') )
       
   104   {
       
   105     warning('System does not support POSIX functions. Termination signals will result in unclean shutdown.');
       
   106   }
       
   107   $httpd = new WebServer($ip, $port);
   117   $httpd = new WebServer($ip, $port);
   108   
   118   
   109   // setup handlers
   119   // setup handlers
   110   status('initializing handlers');
   120   status('initializing handlers');
   111   $httpd->add_handler('index',                'function', 'amarok_playlist');
   121   $httpd->add_handler('index',                'function', 'amarok_playlist');
   141   status("Entering main server loop - ^C to interrupt, listening on port $port");
   151   status("Entering main server loop - ^C to interrupt, listening on port $port");
   142   $httpd->serve();
   152   $httpd->serve();
   143 }
   153 }
   144 catch( Exception $e )
   154 catch( Exception $e )
   145 {
   155 {
       
   156   if ( strstr(strval($e), "Could not bind") )
       
   157   {
       
   158     burnout("Could not bind to the port $ip:$port. Is Greyhound already running? Sometimes browsers don't close off their connections until Greyhound has been dead for about a minute, so try starting Greyhound again in roughly 60 seconds. If that doesn't work, type \"killall -9 php\" at a terminal and try starting Greyhound again in 60 seconds.");
       
   159   }
   146   burnout("Exception caught while running webserver:\n$e");
   160   burnout("Exception caught while running webserver:\n$e");
   147 }
   161 }
   148 
   162 
   149 function handle_refresh_signal()
   163 function handle_refresh_signal()
   150 {
   164 {