{"id":48052,"date":"2024-12-02T14:54:46","date_gmt":"2024-12-02T06:54:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48052\/"},"modified":"2024-12-02T14:54:46","modified_gmt":"2024-12-02T06:54:46","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e6%89%a9%e5%b1%95%e5%88%b0%e4%ba%91%e6%9c%8d%e5%8a%a1%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48052\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f<\/h1>\n<p>\u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p>PHP \u51fd\u6570\u53ef\u901a\u8fc7 Cloud Functions \u6269\u5c55\u5230\u4e91\u670d\u52a1\uff0c\u4ece\u800c\u5229\u7528\u4e91\u8ba1\u7b97\u7684\u4f18\u52bf\u3002\u5b89\u88c5 Cloud Functions \u6269\u5c55\uff1aGoogle Cloud \u4f7f\u7528 Composer\uff0cAzure Functions \u4f7f\u7528 Azure Functions \u6846\u67b6\u3002\u521b\u5efa PHP \u4e91\u51fd\u6570\uff1a\u521b\u5efa\u4e00\u4e2a PHP \u6587\u4ef6\uff08index.php\uff09\u5e76\u5b9a\u4e49\u51fd\u6570\u3002\u90e8\u7f72\u4e91\u51fd\u6570\uff1aGoogle Cloud \u4f7f\u7528 gcloud \u547d\u4ee4\uff0cAzure Functions \u4f7f\u7528 func CLI\u3002\u5b9e\u6218\u6848\u4f8b\uff1a\u4f7f\u7528\u4e91\u51fd\u6570\u5904\u7406\u7535\u5b50\u90ae\u4ef6\uff0c\u89e3\u6790\u7535\u5b50\u90ae\u4ef6\u5e76\u6267\u884c\u903b\u8f91\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729952309671cfa35e793e.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u6269\u5c55\u5230\u4e91\u670d\u52a1\u7684\u6307\u5357<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u51fd\u6570\u662f\u521b\u5efa\u52a8\u6001\u548c\u4ea4\u4e92\u5f0f Web \u5e94\u7528\u7a0b\u5e8f\u7684\u5173\u952e\u90e8\u5206\u3002\u968f\u7740\u4e91\u8ba1\u7b97\u7684\u666e\u53ca\uff0c\u5f00\u53d1\u4eba\u5458\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u5c06\u73b0\u6709\u7684 PHP \u51fd\u6570\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff0c\u4ee5\u5229\u7528\u5176\u53ef\u6269\u5c55\u6027\u548c\u6210\u672c\u6548\u76ca\u3002<\/p>\n<p><strong>\u5b89\u88c5 Cloud Functions<\/strong><\/p>\n<p>\u5bf9\u4e8e Google Cloud\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>composer<\/code> \u5b89\u88c5 Cloud Functions \u6269\u5c55\uff1a<\/p>\n<pre>composer require google\/cloud-functions-framework<\/pre>\n<p>\u5bf9\u4e8e Azure Functions\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>composer require azure\/azure-functions-framework<\/pre>\n<p><strong>\u521b\u5efa PHP \u4e91\u51fd\u6570<\/strong><\/p>\n<p>\u8981\u521b\u5efa\u4e91\u51fd\u6570\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2a PHP \u6587\u4ef6\u5e76\u5c06\u5176\u547d\u540d\u4e3a <code>index.php<\/code>\uff1a<\/p>\n<pre>&lt;?php\nfunction helloWorld(string $name): string {\n  return \"Hello, $name!\";\n}<\/pre>\n<p><strong>\u90e8\u7f72\u4e91\u51fd\u6570<\/strong><\/p>\n<p><strong>Google Cloud<\/strong>\uff1a<\/p>\n<pre>gcloud functions deploy helloWorld --entry-point=helloWorld<\/pre>\n<p><strong>Azure Functions<\/strong>\uff1a<\/p>\n<pre>func azure functionapp publish function-app-name --csharp --csharp<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u4e91\u51fd\u6570\u5904\u7406\u7535\u5b50\u90ae\u4ef6\u7684\u5b9e\u6218\u6848\u4f8b\u3002PHP \u6587\u4ef6\u5c06\u89e3\u6790\u7535\u5b50\u90ae\u4ef6\u5e76\u6267\u884c\u6240\u9700\u7684\u903b\u8f91\uff1a<\/p>\n<pre>&lt;?php\nfunction processEmail(PubSubEvent $event): void {\n  $message = $event-&gt;getData();\n  $payload = json_decode($message, true);\n\n  \/\/ \u6267\u884c\u903b\u8f91\u5904\u7406\u7535\u5b50\u90ae\u4ef6\n}<\/pre>\n<p>\u6b64\u51fd\u6570\u53ef\u90e8\u7f72\u5230\u4e91\u670d\u52a1\uff0c\u5e76\u5728\u6536\u5230\u7535\u5b50\u90ae\u4ef6\u65f6\u81ea\u52a8\u89e6\u53d1\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u5c06 PHP \u51fd\u6570\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5229\u7528\u4e91\u8ba1\u7b97\u7684\u4f18\u52bf\uff0c\u521b\u5efa\u53ef\u6269\u5c55\u4e14\u6210\u672c\u6548\u76ca\u9ad8\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002Cloud Functions \u6269\u5c55\u4f7f\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u5728\u73b0\u6709\u7684\u4ee3\u7801\u57fa\u7840\u4e0a\u6784\u5efa\u5e76\u5728\u4e91\u4e2d\u90e8\u7f72 PHP \u51fd\u6570\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8ephp,\u4e91\u670d\u52a1\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f \u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 PHP \u51fd\u6570\u53ef\u901a\u8fc7 Cloud Functions \u6269\u5c55\u5230\u4e91\u670d\u52a1\uff0c\u4ece\u800c\u5229\u7528\u4e91\u8ba1\u7b97\u7684\u4f18\u52bf\u3002\u5b89\u88c5 Cloud Functions \u6269\u5c55\uff1aGoogle Cloud \u4f7f\u7528 Composer\uff0cAzure Functions \u4f7f\u7528 Azure Functions \u6846\u67b6\u3002\u521b\u5efa PHP \u4e91\u51fd\u6570\uff1a\u521b\u5efa\u4e00\u4e2a PHP \u6587\u4ef6\uff08index.php\uff09\u5e76\u5b9a\u4e49\u51fd\u6570\u3002\u90e8\u7f72\u4e91\u51fd\u6570\uff1aGoogle Cloud \u4f7f\u7528 gcloud \u547d\u4ee4\uff0cAzure Functions \u4f7f\u7528 func CLI\u3002\u5b9e\u6218\u6848\u4f8b\uff1a\u4f7f\u7528\u4e91\u51fd\u6570\u5904\u7406\u7535\u5b50\u90ae\u4ef6\uff0c\u89e3\u6790\u7535\u5b50\u90ae\u4ef6\u5e76\u6267\u884c\u903b\u8f91\u3002 PHP \u51fd\u6570\u6269\u5c55\u5230\u4e91\u670d\u52a1\u7684\u6307\u5357 \u7b80\u4ecb PHP \u51fd\u6570\u662f\u521b\u5efa\u52a8\u6001\u548c\u4ea4\u4e92\u5f0f Web \u5e94\u7528\u7a0b\u5e8f\u7684\u5173\u952e\u90e8\u5206\u3002\u968f\u7740\u4e91\u8ba1\u7b97\u7684\u666e\u53ca\uff0c\u5f00\u53d1\u4eba\u5458\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u5c06\u73b0\u6709\u7684 PHP \u51fd\u6570\u6269\u5c55\u5230\u4e91\u670d\u52a1\uff0c\u4ee5\u5229\u7528\u5176\u53ef\u6269\u5c55\u6027\u548c\u6210\u672c\u6548\u76ca\u3002 \u5b89\u88c5 Cloud Functions \u5bf9\u4e8e Google Cloud\uff0c\u53ef\u4ee5\u901a\u8fc7 composer \u5b89\u88c5 Cloud Functions \u6269\u5c55\uff1a composer require google\/cloud-functions-framework [&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-48052","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48052","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=48052"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48052\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}