{"id":47862,"date":"2024-12-02T09:34:10","date_gmt":"2024-12-02T01:34:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47862\/"},"modified":"2024-12-02T09:34:10","modified_gmt":"2024-12-02T01:34:10","slug":"php%e5%87%bd%e6%95%b0%e4%bb%a3%e7%a0%81%e9%83%a8%e7%bd%b2%e7%9a%84%e6%88%90%e6%9c%ac%e4%bc%98%e5%8c%96%e7%ad%96%e7%95%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47862\/","title":{"rendered":"php\u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aphp\u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p>\u4e3a\u4e86\u964d\u4f4e PHP \u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u6210\u672c\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u7b56\u7565\uff1a\u5229\u7528\u5bb9\u5668\u5316\u90e8\u7f72\uff0c\u7b80\u5316\u53ef\u6269\u5c55\u6027\u548c\u53ef\u79fb\u690d\u6027\uff0c\u51cf\u5c11\u91cd\u590d\u6027\u4efb\u52a1\u7684\u5f00\u9500\u3002\u91c7\u7528\u65e0\u670d\u52a1\u5668\u8ba1\u7b97\uff0c\u53ea\u4e3a\u5b9e\u9645\u4f7f\u7528\u7684\u8d44\u6e90\u4ed8\u8d39\uff0c\u8ba9\u6210\u672c\u4e0e\u6d41\u91cf\u6a21\u5f0f\u4fdd\u6301\u4e00\u81f4\u3002\u4f7f\u7528\u4ee3\u7801\u538b\u7f29\u548c\u4f18\u5316\u6280\u672f\uff0c\u51cf\u5c0f PHP \u4ee3\u7801\u5305\u7684\u5927\u5c0f\uff0c\u964d\u4f4e\u90e8\u7f72\u65f6\u95f4\u548c\u8d44\u6e90\u6d88\u8017\u3002\u901a\u8fc7 CDN \u5c06\u9759\u6001\u6587\u4ef6\u7f13\u5b58\u5230\u79bb\u7528\u6237\u8f83\u8fd1\u7684\u4f4d\u7f6e\uff0c\u51cf\u5c11\u52a0\u8f7d\u65f6\u95f4\u548c\u5e26\u5bbd\u4f7f\u7528\u91cf\u3002\u4f7f\u7528 CI\/CD \u5de5\u5177\u81ea\u52a8\u5316\u90e8\u7f72\u8fc7\u7a0b\uff0c\u51cf\u5c11\u4eba\u5de5\u9519\u8bef\uff0c\u63d0\u9ad8\u6548\u7387\u548c\u4e00\u81f4\u6027\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729940258671ccb22d27c0.jpg\" class=\"aligncenter\" title=\"php\u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565\u63d2\u56fe\" alt=\"php\u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u6210\u672c\u4f18\u5316\u7b56\u7565<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u5728\u73b0\u4ee3\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\uff0cPHP \u51fd\u6570\u4ee3\u7801\u7684\u90e8\u7f72\u6210\u672c\u53ef\u80fd\u53d8\u5f97\u6602\u8d35\u3002\u901a\u8fc7\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\uff0c\u4f60\u53ef\u4ee5\u663e\u7740\u964d\u4f4e\u8fd9\u4e9b\u6210\u672c\u3002<\/p>\n<p><strong>1. \u5bb9\u5668\u5316\u90e8\u7f72<\/strong><\/p>\n<p>\u901a\u8fc7\u5c06 PHP \u4ee3\u7801\u6253\u5305\u5230\u8f7b\u91cf\u7ea7\u5bb9\u5668\u4e2d\uff08\u4f8b\u5982 Docker\uff09\uff0c\u4f60\u53ef\u4ee5\u5229\u7528\u5bb9\u5668\u7f16\u6392\u7cfb\u7edf\uff08\u4f8b\u5982 Kubernetes\uff09\u6765\u7ba1\u7406\u90e8\u7f72\u3002\u8fd9\u7b80\u5316\u4e86\u53ef\u6269\u5c55\u6027\u548c\u53ef\u79fb\u690d\u6027\uff0c\u5e76\u51cf\u5c11\u4e86\u91cd\u590d\u6027\u4efb\u52a1\u7684\u5f00\u9500\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre># composer.json \u6587\u4ef6\n{\n  \"require\": {\n    \"my-function\": \"1.0.*\"\n  },\n  \"autoload\": {\n    \"psr-4\": {\n      \"My\\\\Function\\\\\": \"src\/\"\n    }\n  }\n}<\/pre>\n<pre># Dockerfile \u6587\u4ef6\nFROM php:7.4-apache\n\nWORKDIR \/app\n\nCOPY composer.json composer.lock .\/\n\nRUN composer install\n\nCOPY src .\/\n\nCMD [\"php\", \"index.php\"]<\/pre>\n<p><strong>2. \u65e0\u670d\u52a1\u5668\u8ba1\u7b97<\/strong><\/p>\n<p>\u4f7f\u7528\u65e0\u670d\u52a1\u5668\u5e73\u53f0\uff08\u4f8b\u5982 AWS Lambda \u6216 Azure Functions\uff09\u53ef\u4ee5\u4ec5\u4e3a\u4f60\u5b9e\u9645\u4f7f\u7528\u7684\u8d44\u6e90\u4ed8\u8d39\u3002\u8fd9\u6d88\u9664\u4e86\u670d\u52a1\u5668\u7ba1\u7406\u8d39\u7528\uff0c\u5e76\u4f7f\u6210\u672c\u4e0e\u6d41\u91cf\u6a21\u5f0f\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre># index.php \u6587\u4ef6\n&lt;?php\n\nuse My\\Function\\Function;\n\n$function = new Function();\n$result = $function-&gt;execute();\n\necho $result;<\/pre>\n<p><strong>3. \u4ee3\u7801\u5927\u5c0f\u4f18\u5316<\/strong><\/p>\n<p>\u8f83\u5c0f\u7684\u4ee3\u7801\u5305\u51cf\u5c11\u4e86\u90e8\u7f72\u65f6\u95f4\u548c\u8d44\u6e90\u6d88\u8017\u3002\u4f7f\u7528\u4ee3\u7801\u538b\u7f29\u3001\u6811\u72b6\u6447\u6811\uff08tree-shaking\uff09\u548c\u5176\u4ed6\u4f18\u5316\u6280\u672f\u6765\u51cf\u5c0f PHP \u4ee3\u7801\u5305\u7684\u5927\u5c0f\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre># webpack.config.js \u6587\u4ef6\nmodule.exports = {\n  \/\/ ...\n  optimization: {\n    minimize: true,\n    usedExports: true\n  }\n};<\/pre>\n<p><strong>4. \u4f7f\u7528 CDN<\/strong><\/p>\n<p>\u5185\u5bb9\u5206\u53d1\u7f51\u7edc\uff08CDN\uff09\u5c06\u9759\u6001\u6587\u4ef6\u7f13\u5b58\u5230\u79bb\u7528\u6237\u8f83\u8fd1\u7684\u4f4d\u7f6e\uff0c\u4ece\u800c\u51cf\u5c11\u4e86\u52a0\u8f7d\u65f6\u95f4\u548c\u5e26\u5bbd\u4f7f\u7528\u91cf\u3002\u5bf9\u4e8e PHP \u4ee3\u7801\u90e8\u7f72\u4e2d\u7684\u9759\u6001\u8d44\u6e90\uff08\u4f8b\u5982\u56fe\u50cf\u6216 CSS\uff09\uff0cCDN \u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u548c\u964d\u4f4e\u6210\u672c\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre># my-app.php \u6587\u4ef6\n&lt;?php\n\nuse Cloudinary\\Cloudinary;\nuse Cloudinary\\Configuration\\CloudinaryConfiguration;\n\n$config = new CloudinaryConfiguration([\n  \"cloud\" =&gt; [\n    \"cloud_name\" =&gt; \"cloudinary-user\",\n    \"api_key\"    =&gt; \"MY_API_KEY\",\n    \"api_secret\" =&gt; \"MY_API_SECRET\"\n  ]\n]);\n$cloudinary = new Cloudinary($config);\n<\/pre>\n<p><strong>5. \u81ea\u52a8\u5316\u90e8\u7f72<\/strong><\/p>\n<p>\u4f7f\u7528\u6301\u7eed\u96c6\u6210\u548c\u6301\u7eed\u90e8\u7f72\uff08CI\/CD\uff09\u5de5\u5177\u81ea\u52a8\u5316\u90e8\u7f72\u8fc7\u7a0b\u3002\u8fd9\u51cf\u5c11\u4e86\u4eba\u5de5\u9519\u8bef\uff0c\u63d0\u9ad8\u4e86\u6548\u7387\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u7248\u672c\u63a7\u5236\u548c\u6d4b\u8bd5\u6765\u786e\u4fdd\u4e00\u81f4\u6027\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>pipeline:\n  build:\n    image: google\/cloud-sdk:latest\n    commands:\n      # ...\n      - gcloud functions deploy my-function<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u5b9e\u65bd\u8fd9\u4e9b\u7b56\u7565\uff0c\u4f60\u53ef\u4ee5\u663e\u7740\u4f18\u5316 PHP \u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u3002\u5bb9\u5668\u5316\u3001\u65e0\u670d\u52a1\u5668\u8ba1\u7b97\u3001\u4ee3\u7801\u5927\u5c0f\u4f18\u5316\u3001CDN \u4f7f\u7528\u548c\u90e8\u7f72\u81ea\u52a8\u5316\u5c06\u6709\u52a9\u4e8e\u964d\u4f4e\u8d44\u6e90\u6d88\u8017\u3001\u63d0\u9ad8\u6027\u80fd\u5e76\u964d\u4f4e\u8fd0\u8425\u6210\u672c\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aphp\u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565\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\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565 \u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aphp\u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u7684\u6210\u672c\u4f18\u5316\u7b56\u7565\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002 \u4e3a\u4e86\u964d\u4f4e PHP \u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u6210\u672c\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u7b56\u7565\uff1a\u5229\u7528\u5bb9\u5668\u5316\u90e8\u7f72\uff0c\u7b80\u5316\u53ef\u6269\u5c55\u6027\u548c\u53ef\u79fb\u690d\u6027\uff0c\u51cf\u5c11\u91cd\u590d\u6027\u4efb\u52a1\u7684\u5f00\u9500\u3002\u91c7\u7528\u65e0\u670d\u52a1\u5668\u8ba1\u7b97\uff0c\u53ea\u4e3a\u5b9e\u9645\u4f7f\u7528\u7684\u8d44\u6e90\u4ed8\u8d39\uff0c\u8ba9\u6210\u672c\u4e0e\u6d41\u91cf\u6a21\u5f0f\u4fdd\u6301\u4e00\u81f4\u3002\u4f7f\u7528\u4ee3\u7801\u538b\u7f29\u548c\u4f18\u5316\u6280\u672f\uff0c\u51cf\u5c0f PHP \u4ee3\u7801\u5305\u7684\u5927\u5c0f\uff0c\u964d\u4f4e\u90e8\u7f72\u65f6\u95f4\u548c\u8d44\u6e90\u6d88\u8017\u3002\u901a\u8fc7 CDN \u5c06\u9759\u6001\u6587\u4ef6\u7f13\u5b58\u5230\u79bb\u7528\u6237\u8f83\u8fd1\u7684\u4f4d\u7f6e\uff0c\u51cf\u5c11\u52a0\u8f7d\u65f6\u95f4\u548c\u5e26\u5bbd\u4f7f\u7528\u91cf\u3002\u4f7f\u7528 CI\/CD \u5de5\u5177\u81ea\u52a8\u5316\u90e8\u7f72\u8fc7\u7a0b\uff0c\u51cf\u5c11\u4eba\u5de5\u9519\u8bef\uff0c\u63d0\u9ad8\u6548\u7387\u548c\u4e00\u81f4\u6027\u3002 PHP \u51fd\u6570\u4ee3\u7801\u90e8\u7f72\u6210\u672c\u4f18\u5316\u7b56\u7565 \u5f15\u8a00 \u5728\u73b0\u4ee3\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\uff0cPHP \u51fd\u6570\u4ee3\u7801\u7684\u90e8\u7f72\u6210\u672c\u53ef\u80fd\u53d8\u5f97\u6602\u8d35\u3002\u901a\u8fc7\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\uff0c\u4f60\u53ef\u4ee5\u663e\u7740\u964d\u4f4e\u8fd9\u4e9b\u6210\u672c\u3002 1. \u5bb9\u5668\u5316\u90e8\u7f72 \u901a\u8fc7\u5c06 PHP \u4ee3\u7801\u6253\u5305\u5230\u8f7b\u91cf\u7ea7\u5bb9\u5668\u4e2d\uff08\u4f8b\u5982 Docker\uff09\uff0c\u4f60\u53ef\u4ee5\u5229\u7528\u5bb9\u5668\u7f16\u6392\u7cfb\u7edf\uff08\u4f8b\u5982 Kubernetes\uff09\u6765\u7ba1\u7406\u90e8\u7f72\u3002\u8fd9\u7b80\u5316\u4e86\u53ef\u6269\u5c55\u6027\u548c\u53ef\u79fb\u690d\u6027\uff0c\u5e76\u51cf\u5c11\u4e86\u91cd\u590d\u6027\u4efb\u52a1\u7684\u5f00\u9500\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a # composer.json \u6587\u4ef6 { &#8220;require&#8221;: { &#8220;my-function&#8221;: &#8220;1.0.*&#8221; }, &#8220;autoload&#8221;: { &#8220;psr-4&#8221;: { &#8220;My\\\\Function\\\\&#8221;: &#8220;src\/&#8221; } } } # Dockerfile \u6587\u4ef6 FROM php:7.4-apache WORKDIR \/app COPY composer.json composer.lock .\/ RUN composer [&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-47862","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47862","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=47862"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47862\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}