Skip to content

Instantly share code, notes, and snippets.

@burnsjeremy
Forked from webjay/gh_hook.php
Created February 14, 2013 16:10

Revisions

  1. @webjay webjay revised this gist Oct 19, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gh_hook.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@

    function syscall ($cmd, $cwd) {
    $descriptorspec = array(
    1 => array('pipe', 'w'), // stdout is a pipe that the child will write to
    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)) {
  2. @webjay webjay revised this gist Oct 19, 2012. 1 changed file with 26 additions and 27 deletions.
    53 changes: 26 additions & 27 deletions gh_hook.php
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,35 @@
    <?php

    <?php
    //error_reporting(E_ALL);
    ignore_user_abort(true);

    //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;
    }
    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'])) {
    // 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');
    // pull from master
    $result = syscall('git pull', '/var/www/example.com');

    // send us the output
    mail('[email protected]', 'GitHub hook `git pull` result', $result);
    // send us the output
    mail('[email protected]', 'GitHub hook `git pull` result', $result);

    // clear APC
    if (apc_clear_cache('opcode') == false) {
    mail('root', 'Unable to apc_clear_cache()', '');
    }

    // clear APC
    if (apc_clear_cache('opcode') == false) {
    mail('root', 'Unable to apc_clear_cache()', '');
    }

    }

    ?>
    ?>
  3. @webjay webjay created this gist Oct 19, 2012.
    36 changes: 36 additions & 0 deletions gh_hook.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@

    <?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('[email protected]', 'GitHub hook `git pull` result', $result);

    // clear APC
    if (apc_clear_cache('opcode') == false) {
    mail('root', 'Unable to apc_clear_cache()', '');
    }

    }

    ?>