Skip to content

Instantly share code, notes, and snippets.

@ralphschindler
Created September 22, 2012 15:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ralphschindler/3766520 to your computer and use it in GitHub Desktop.
Save ralphschindler/3766520 to your computer and use it in GitHub Desktop.
Script to be used with PHP's built-in webserver to proxy and spider a site on click
<?php
// start PHP with: php -S localhost:8888 -t . spider.php
$site = 'http://www.targetwebsite.org/';
$path = $_SERVER["REQUEST_URI"];
if ($path == '/') {
$path = '/index.html';
}
if (file_exists(__DIR__ . $path)) {
return false;
}
$content = file_get_contents($site . $path);
if (strpos(ltrim($path, '/'), '/')) {
if (!file_exists(__DIR__ . dirname($path))) {
mkdir(__DIR__ . dirname($path), 0777, true);
}
}
file_put_contents(__DIR__ . rawurldecode($path), $content);
sleep(1);
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment