Skip to content

Instantly share code, notes, and snippets.

@burnsjeremy
Forked from webjay/gh_hook.php
Created February 14, 2013 16:10
Show Gist options
  • Save burnsjeremy/4953839 to your computer and use it in GitHub Desktop.
Save burnsjeremy/4953839 to your computer and use it in GitHub Desktop.
<?php
//error_reporting(E_ALL);
ignore_user_abort(true);
function syscall ($cmd, $cwd) {
$descriptorspec = array(
1 => array('pipe', 'w') // stdout is a pipe that the child will write to
);
$resource = proc_open($cmd, $descriptorspec, $pipes, $cwd);
if (is_resource($resource)) {
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($resource);
return $output;
}
}
// GitHub will hit us with POST (http://help.github.com/post-receive-hooks/)
if (!empty($_POST['payload'])) {
// pull from master
$result = syscall('git pull', '/var/www/example.com');
// send us the output
mail('team@example.com', 'GitHub hook `git pull` result', $result);
// clear APC
if (apc_clear_cache('opcode') == false) {
mail('root', 'Unable to apc_clear_cache()', '');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment