{"id":47184,"date":"2024-12-02T08:35:08","date_gmt":"2024-12-02T00:35:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47184\/"},"modified":"2024-12-02T08:35:08","modified_gmt":"2024-12-02T00:35:08","slug":"php-%e5%87%bd%e6%95%b0%e7%89%88%e6%9c%ac%e6%9b%b4%e6%96%b0%e6%8c%87%e5%8d%97%ef%bc%9a%e6%8c%81%e7%bb%ad%e9%9b%86%e6%88%90%e5%92%8c%e8%87%aa%e5%8a%a8%e5%8c%96","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47184\/","title":{"rendered":"PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aPHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0 PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u7684\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\uff0c\u60a8\u9700\u8981\uff1a\u4f7f\u7528 Git \u548c\u7248\u672c\u63a7\u5236\u521b\u5efa\u5b58\u50a8\u5e93\u3002\u8bbe\u7f6e\u6301\u7eed\u96c6\u6210\u7ba1\u9053\uff08\u5982 GitHub Actions\uff09\u6765\u5b89\u88c5\u4f9d\u8d56\u9879\u3001\u8fd0\u884c\u6d4b\u8bd5\u548c\u90e8\u7f72\u51fd\u6570\u3002\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\uff0c\u5176\u4e2d\u5305\u62ec\u4f7f\u7528 HTTP \u5ba2\u6237\u7aef\u63d0\u53d6\u6700\u65b0\u7248\u672c\u3001\u4e0e\u5f53\u524d\u7248\u672c\u8fdb\u884c\u6bd4\u8f83\u5e76\u90e8\u7f72\u65b0\u7248\u672c\u7684\u6b65\u9aa4\u3002\u5c06\u90e8\u7f72\u811a\u672c\u914d\u7f6e\u4e3a\u5728 CI\/CD \u7ba1\u9053\u4e2d\u8fd0\u884c\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\u7ed9\u51fa\u4e86\u4e00\u4e2a\u7528\u4e8e\u8ba1\u7b97\u7528\u6237\u8ba2\u5355\u603b\u989d\u7684 PHP \u51fd\u6570\u793a\u4f8b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729902994671c3992752b3.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u5b9e\u73b0\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0c\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u81ea\u52a8\u5316\u51fd\u6570\u7248\u672c\u66f4\u65b0\uff0c\u6211\u4eec\u53ef\u4ee5\u8282\u7701\u65f6\u95f4\uff0c\u907f\u514d\u9519\u8bef\u5e76\u63d0\u9ad8\u751f\u4ea7\u529b\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u4f7f\u7528\u793a\u4f8b\u4ee3\u7801\u5b9e\u73b0 PHP \u51fd\u6570\u7248\u672c\u7684\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u3002<\/p>\n<p><strong>\u4f7f\u7528 Git \u548c\u7248\u672c\u63a7\u5236<\/strong><\/p>\n<p>\u521b\u5efa Git \u5b58\u50a8\u5e93\u4ee5\u8ddf\u8e2a\u51fd\u6570\u4ee3\u7801\u7684\u66f4\u6539\u3002\u6bcf\u6b21\u8fdb\u884c\u66f4\u6539\u540e\uff0c\u90fd\u5e94\u63d0\u4ea4\u548c\u63a8\u9001\u66f4\u6539\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u8fd9\u5c06\u4f5c\u4e3a\u66f4\u6539\u5386\u53f2\u7684\u8bb0\u5f55\uff0c\u5e76\u5141\u8bb8\u60a8\u8f7b\u677e\u56de\u6eda\u5230\u4ee5\u524d\u7684\u7248\u672c\u3002<\/p>\n<p><strong>\u8bbe\u7f6e\u6301\u7eed\u96c6\u6210\u7ba1\u9053<\/strong><\/p>\n<p>\u4f7f\u7528\u6301\u7eed\u96c6\u6210\u670d\u52a1\uff0c\u4f8b\u5982 GitHub Actions \u6216 GitLab CI\uff0c\u914d\u7f6e CI\/CD \u7ba1\u9053\u3002\u5f53\u4ee3\u7801\u63d0\u4ea4\u5230\u5b58\u50a8\u5e93\u65f6\uff0c\u7ba1\u9053\u5c06\u81ea\u52a8\u89e6\u53d1\u5e76\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li><strong>\u5b89\u88c5\u4f9d\u8d56\u9879\uff1a<\/strong>\u8fd0\u884c<code>composer install<\/code>\u6216<code>npm install<\/code>\u6765\u5b89\u88c5\u51fd\u6570\u6240\u9700\u7684\u4f9d\u8d56\u9879\u3002<\/li>\n<li><strong>\u8fd0\u884c\u6d4b\u8bd5\uff1a<\/strong>\u4f7f\u7528 PHPUnit \u6216 Codeception \u7b49\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\u8fd0\u884c\u6d4b\u8bd5\u4ee5\u786e\u4fdd\u51fd\u6570\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n<li><strong>\u90e8\u7f72\u51fd\u6570\uff1a<\/strong>\u4f7f\u7528 Google Cloud Functions\u3001AWS Lambda \u6216 Azure Functions \u7b49\u65e0\u670d\u52a1\u5668\u5e73\u53f0\u5c06\u51fd\u6570\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u3002<\/li>\n<\/ul>\n<p><strong>\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c<\/strong><\/p>\n<p>\u521b\u5efa\u811a\u672c\u4ee5\u81ea\u52a8\u5316\u51fd\u6570\u7248\u672c\u66f4\u65b0\u6d41\u7a0b\uff1a<\/p>\n<pre>&lt;?php\n\nuse GuzzleHttp\\Client;\nuse GuzzleHttp\\HandlerStack;\n\n\/\/ \u521b\u5efa\u5e26\u6709\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u7684 HTTP \u5ba2\u6237\u7aef\n$stack = HandlerStack::create();\n$stack-&gt;push(GuzzleHttp\\Middleware::basicAuth($username, $password));\n$client = new Client(['handler' =&gt; $stack]);\n\n\/\/ \u83b7\u53d6\u51fd\u6570\u7684\u6700\u65b0\u7248\u672c\n$response = $client-&gt;get('https:\/\/&lt;your-domain&gt;\/api\/functions\/&lt;your-function&gt;');\n\n\/\/ \u63d0\u53d6\u51fd\u6570\u7248\u672c\n$json = json_decode($response-&gt;getBody()-&gt;getContents(), true);\n$newVersion = $json['version'];\n\n\/\/ \u68c0\u67e5\u5f53\u524d\u7248\u672c\u662f\u5426\u4e0e\u6700\u65b0\u7248\u672c\u4e0d\u540c\nif ($newVersion != $currentVersion) {\n  \/\/ \u90e8\u7f72\u51fd\u6570\u7684\u65b0\u7248\u672c\n  $result = $client-&gt;post('https:\/\/&lt;your-domain&gt;\/api\/functions\/&lt;your-function&gt;\/deploy', [\n    'form_params' =&gt; ['version' =&gt; $newVersion]\n  ]);\n\n  \/\/ \u68c0\u67e5\u90e8\u7f72\u662f\u5426\u6210\u529f\n  if ($result-&gt;getStatusCode() == 200) {\n    echo \"\u51fd\u6570\u90e8\u7f72\u6210\u529f\u3002\";\n  } else {\n    \/\/ \u90e8\u7f72\u5931\u8d25\uff0c\u629b\u51fa\u5f02\u5e38\n    throw new RuntimeException(\"\u51fd\u6570\u90e8\u7f72\u5931\u8d25\u3002\");\n  }\n} else {\n  echo \"\u51fd\u6570\u7248\u672c\u5df2\u662f\u6700\u65b0\u3002\";\n}<\/pre>\n<p><strong>\u90e8\u7f72\u811a\u672c<\/strong><\/p>\n<p>\u5c06\u81ea\u52a8\u5316\u811a\u672c\u914d\u7f6e\u4e3a\u5728 CI\/CD \u7ba1\u9053\u4e2d\u8fd0\u884c\u3002\u5f53 CI\/CD \u7ba1\u9053\u6210\u529f\u8fd0\u884c\u65f6\uff0c\u5c06\u81ea\u52a8\u66f4\u65b0\u51fd\u6570\u7248\u672c\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u7528\u4e8e\u8ba1\u7b97\u7528\u6237\u8ba2\u5355\u603b\u989d\u7684 PHP \u51fd\u6570\uff1a<\/p>\n<pre>&lt;?php\n\nuse GuzzleHttp\\Client;\nuse GuzzleHttp\\HandlerStack;\n\n\/\/ \u83b7\u53d6\u7528\u6237\u8ba2\u5355\nfunction getTotalAmount($userId)\n{\n  $client = new Client();\n\n  $response = $client-&gt;get('https:\/\/&lt;your-domain&gt;\/api\/orders\/' . $userId);\n  $orders = json_decode($response-&gt;getBody()-&gt;getContents(), true);\n\n  \/\/ \u8ba1\u7b97\u603b\u91d1\u989d\n  $totalAmount = 0;\n  foreach ($orders as $order) {\n    $totalAmount += $order['amount'];\n  }\n\n  return $totalAmount;\n}\n?&gt;<\/pre>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e0a\u9762\u63d0\u4f9b\u7684\u6307\u5357\u5b9e\u73b0\u51fd\u6570\u7248\u672c\u7684\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u3002\u8fd9\u5c06\u6709\u52a9\u4e8e\u4fdd\u6301\u51fd\u6570\u7684\u6700\u65b0\u72b6\u6001\u5e76\u63d0\u9ad8\u5176\u53ef\u9760\u6027\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aPHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316 \u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aPHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ \u4e3a\u4e86\u5b9e\u73b0 PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u7684\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\uff0c\u60a8\u9700\u8981\uff1a\u4f7f\u7528 Git \u548c\u7248\u672c\u63a7\u5236\u521b\u5efa\u5b58\u50a8\u5e93\u3002\u8bbe\u7f6e\u6301\u7eed\u96c6\u6210\u7ba1\u9053\uff08\u5982 GitHub Actions\uff09\u6765\u5b89\u88c5\u4f9d\u8d56\u9879\u3001\u8fd0\u884c\u6d4b\u8bd5\u548c\u90e8\u7f72\u51fd\u6570\u3002\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\uff0c\u5176\u4e2d\u5305\u62ec\u4f7f\u7528 HTTP \u5ba2\u6237\u7aef\u63d0\u53d6\u6700\u65b0\u7248\u672c\u3001\u4e0e\u5f53\u524d\u7248\u672c\u8fdb\u884c\u6bd4\u8f83\u5e76\u90e8\u7f72\u65b0\u7248\u672c\u7684\u6b65\u9aa4\u3002\u5c06\u90e8\u7f72\u811a\u672c\u914d\u7f6e\u4e3a\u5728 CI\/CD \u7ba1\u9053\u4e2d\u8fd0\u884c\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\u7ed9\u51fa\u4e86\u4e00\u4e2a\u7528\u4e8e\u8ba1\u7b97\u7528\u6237\u8ba2\u5355\u603b\u989d\u7684 PHP \u51fd\u6570\u793a\u4f8b\u3002 PHP \u51fd\u6570\u7248\u672c\u66f4\u65b0\u6307\u5357\uff1a\u5b9e\u73b0\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316 \u5f15\u8a00 \u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0c\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u81ea\u52a8\u5316\u51fd\u6570\u7248\u672c\u66f4\u65b0\uff0c\u6211\u4eec\u53ef\u4ee5\u8282\u7701\u65f6\u95f4\uff0c\u907f\u514d\u9519\u8bef\u5e76\u63d0\u9ad8\u751f\u4ea7\u529b\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u4f7f\u7528\u793a\u4f8b\u4ee3\u7801\u5b9e\u73b0 PHP \u51fd\u6570\u7248\u672c\u7684\u6301\u7eed\u96c6\u6210\u548c\u81ea\u52a8\u5316\u3002 \u4f7f\u7528 Git \u548c\u7248\u672c\u63a7\u5236 \u521b\u5efa Git \u5b58\u50a8\u5e93\u4ee5\u8ddf\u8e2a\u51fd\u6570\u4ee3\u7801\u7684\u66f4\u6539\u3002\u6bcf\u6b21\u8fdb\u884c\u66f4\u6539\u540e\uff0c\u90fd\u5e94\u63d0\u4ea4\u548c\u63a8\u9001\u66f4\u6539\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u8fd9\u5c06\u4f5c\u4e3a\u66f4\u6539\u5386\u53f2\u7684\u8bb0\u5f55\uff0c\u5e76\u5141\u8bb8\u60a8\u8f7b\u677e\u56de\u6eda\u5230\u4ee5\u524d\u7684\u7248\u672c\u3002 \u8bbe\u7f6e\u6301\u7eed\u96c6\u6210\u7ba1\u9053 \u4f7f\u7528\u6301\u7eed\u96c6\u6210\u670d\u52a1\uff0c\u4f8b\u5982 GitHub Actions \u6216 GitLab CI\uff0c\u914d\u7f6e CI\/CD \u7ba1\u9053\u3002\u5f53\u4ee3\u7801\u63d0\u4ea4\u5230\u5b58\u50a8\u5e93\u65f6\uff0c\u7ba1\u9053\u5c06\u81ea\u52a8\u89e6\u53d1\u5e76\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u5b89\u88c5\u4f9d\u8d56\u9879\uff1a\u8fd0\u884ccomposer install\u6216npm install\u6765\u5b89\u88c5\u51fd\u6570\u6240\u9700\u7684\u4f9d\u8d56\u9879\u3002 \u8fd0\u884c\u6d4b\u8bd5\uff1a\u4f7f\u7528 PHPUnit \u6216 Codeception \u7b49\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\u8fd0\u884c\u6d4b\u8bd5\u4ee5\u786e\u4fdd\u51fd\u6570\u6b63\u5e38\u5de5\u4f5c\u3002 \u90e8\u7f72\u51fd\u6570\uff1a\u4f7f\u7528 Google Cloud Functions\u3001AWS Lambda \u6216 Azure Functions \u7b49\u65e0\u670d\u52a1\u5668\u5e73\u53f0\u5c06\u51fd\u6570\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47184","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47184"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47184\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}