Webhook's PHP practice @coding.net

Source: Internet
Author: User
Tags vps filezilla webhook

Every time you write the code, open the FileZilla, write the file uploaded to the VPS, over the longer feel bored, wondering if there is more geek method, there is this article.
Webhook is the technology that comes with git, when you push to the server, the server sends a special request to the URL you specify, and we can use the scripting language to get the request and execute the GIT pull on the VPS to achieve the purpose of automatic deployment, the usual first code :

<?php/** * Simple Git WebHook SDK * * @coding. NET * 2016/05/09 * author:hldh214 <[email protected]> * *//configuration item Start$git _dir='/var/www/.git ';$work _tree='/var/www ';//Configuration item End//Get the original request$hook _log= File_get_contents (' Php://input ');//Use MySQL log log$fh= Mysqli_connect (' localhost ',' Root ',' Root ',' git ');//Determine if the request is Webhookif(!Empty($hook _log)) {//Is Webhook request, and decode data    $json= Json_decode ($hook _log,true);if(Array_key_exists (' ref ',$json)) {//Ref key detected, execute pull        $cmd="/usr/bin/sudo git--git-dir= $git _dir--work-tree= $work _tree pull 2>&1";$sh _log= Shell_exec ($cmd);$sql="INSERT into ' webhook_log ' (' Hook_log ', ' sh_log ', ' Date ') VALUES ('".$hook _log."', '".$sh _log."', Current_date ());";//Log execution Log        $result= Mysqli_query ($fh,$sql); }Else{//No ref key detected, for test request        $sh _log=' testing ';$sql="INSERT into ' webhook_log ' (' Hook_log ', ' sh_log ', ' Date ') VALUES ('".$hook _log."', '".$sh _log."', Current_date ());";$result= Mysqli_query ($fh,$sql); }}Else{//Normal access    Echo ' ;}

Upload this code to the VPS with FileZilla (the last time you use FileZilla <3), fill in the URL of the php file into the deploy_url of the Webhook page, and click Test, Then go back to the VPS to see if MySQL already has log, and then try Commit&push in the development machine, you will find that the code has been quietly deployed to the VPS.

Webhook's PHP practice @coding.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.