$handler = new $handlerClass($hconf->options->toArray()); $handler->setHandlerName($name); $engine->addHandler($handler); } } // If we have pcntl - set up a handler for sigterm if (function_exists('pcntl_signal')) { declare (ticks=1); pcntl_signal(SIGABRT, 'do_exit'); pcntl_signal(SIGHUP, 'do_exit'); pcntl_signal(SIGQUIT, 'do_exit'); pcntl_signal(SIGINT, 'do_exit'); pcntl_signal(SIGTERM, 'do_exit'); } // Go! $engine->run($url); //run queue's //var_dump($queue); do_exit(); /** * ------- * Execution ends here - Some functions are defined next * ------- */ /** * Show usage message * * @return void */ function spizer_usage() {
pcntl_signal(SIGQUIT, 'do_exit'); pcntl_signal(SIGINT, 'do_exit'); pcntl_signal(SIGTERM, 'do_exit'); } // Instantiate Spizer engine $spizer = new Spizer_Engine(array('delay' => $delay, 'savecookies' => $opts->savecookies, 'lifo' => true)); // Set logger $logger = new Spizer_Logger_Sqlite(array('dbfile' => $log)); $spizer->setLogger($logger); // Set the spider to follow links, hrefs, images and script references $spizer->addHandler(new Spizer_Handler_LinkAppender(array('domain' => parse_url($url, PHP_URL_HOST)))); // Add some handlers to be executed on 200 OK + text/html pages $spizer->addHandler(new Spizer_Handler_StringMatch(array('match' => 'error', 'matchcase' => false, 'status' => 200, 'content-type' => 'text/html'))); $spizer->addHandler(new Spizer_Handler_StringMatch(array('match' => 'warning', 'matchcase' => false, 'status' => 200, 'content-type' => 'text/html'))); // Go! $spizer->run($url); do_exit(); // -- end here -- // Some functions function spizer_usage() { if (!isset($argv)) { $argv = $_SERVER['argv']; } echo <<<USAGE Spizer - the flexible web spider, v. 0.1 Usage: {$argv[0]} [options] <Start URL> Where [options] can be: --delay | -d <seconds> Number of seconds to delay between requests --log | -l <log file> Send messages to file instead of to stdout