Created
January 17, 2019 05:35
-
-
Save hteen/43481d53617237b4346be508bbe4674a to your computer and use it in GitHub Desktop.
simple webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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