Skip to content

Instantly share code, notes, and snippets.

@hteen
Created January 17, 2019 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hteen/43481d53617237b4346be508bbe4674a to your computer and use it in GitHub Desktop.
Save hteen/43481d53617237b4346be508bbe4674a to your computer and use it in GitHub Desktop.
simple webhook
<?php
$http = new swoole_http_server("0.0.0.0", 80);
$http->on("start", function ($server) {
echo "Swoole http server is started\n";
});
$http->on("request", function ($request, $response) {
$response->header("Content-Type", "text/plain");
// Gitee Push
if(strtolower($request->server['request_method']) == 'post'){
$data = json_decode($request->rawContent(), true);
$dir = $data['password'] ?? '';
if ($dir && is_dir("/data/www/$dir")) {
$path = "/data/www/$dir";
exec("echo `date` >> /data/log/pull.log && cd $path && git pull >> /data/log/pull.log > /dev/null 2>/dev/null &");
}
$response->end('ok');
}
// Show Log
else {
$content = file_get_contents("/data/log/pull.log");
$response->end($content);
}
});
$http->start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment