{"id":46750,"date":"2024-12-02T09:25:02","date_gmt":"2024-12-02T01:25:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46750\/"},"modified":"2024-12-02T09:25:02","modified_gmt":"2024-12-02T01:25:02","slug":"php-%e5%87%bd%e6%95%b0%e6%89%a9%e5%b1%95%e4%b8%8e-c-%e8%af%ad%e8%a8%80%e6%89%a9%e5%b1%95%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46750\/","title":{"rendered":"PHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/h1>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729844398671b54ae2d026.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u7684\u533a\u522b<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u6269\u5c55\u4f7f\u7a0b\u5e8f\u5458\u80fd\u591f\u901a\u8fc7\u52a0\u8f7d\u52a8\u6001\u94fe\u63a5\u5e93 (DLL) \u6216\u5171\u4eab\u5bf9\u8c61 (SO) \u6765\u6269\u5c55 PHP \u7684\u529f\u80fd\u3002\u8fd9\u4e9b\u6269\u5c55\u53ef\u4ee5\u662f\u51fd\u6570\u6269\u5c55\uff08\u7528 PHP \u7f16\u5199\uff09\u6216 C \u8bed\u8a00\u6269\u5c55\u3002\u672c\u6587\u5c06\u63a2\u8ba8 PHP \u51fd\u6570\u6269\u5c55\u548c C \u8bed\u8a00\u6269\u5c55\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\u3002<\/p>\n<p><strong>\u5b9e\u73b0<\/strong><\/p>\n<ul>\n<li><strong>PHP \u51fd\u6570\u6269\u5c55\uff1a<\/strong>\u7528 PHP \u7f16\u5199\uff0c\u7136\u540e\u7f16\u8bd1\u6210\u5171\u4eab\u5bf9\u8c61\u3002<\/li>\n<li><strong>C \u8bed\u8a00\u6269\u5c55\uff1a<\/strong>\u7528 C \u8bed\u8a00\u7f16\u5199\uff0c\u7136\u540e\u7f16\u8bd1\u6210 DLL\/SO\u3002<\/li>\n<\/ul>\n<p><strong>\u6027\u80fd<\/strong><\/p>\n<ul>\n<li><strong>PHP \u51fd\u6570\u6269\u5c55\uff1a<\/strong>\u901a\u5e38\u6bd4 C \u8bed\u8a00\u6269\u5c55\u6027\u80fd\u8f83\u4f4e\uff0c\u56e0\u4e3a PHP \u662f\u89e3\u91ca\u6027\u8bed\u8a00\u3002<\/li>\n<li><strong>C \u8bed\u8a00\u6269\u5c55\uff1a<\/strong>\u6027\u80fd\u66f4\u9ad8\uff0c\u56e0\u4e3a C \u8bed\u8a00\u662f\u7f16\u8bd1\u6027\u8bed\u8a00\u3002<\/li>\n<\/ul>\n<p><strong>\u7f16\u5199\u96be\u5ea6<\/strong><\/p>\n<ul>\n<li><strong>PHP \u51fd\u6570\u6269\u5c55\uff1a<\/strong>\u901a\u5e38\u66f4\u5bb9\u6613\u7f16\u5199\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5229\u7528 PHP \u7684\u8bed\u6cd5\u548c\u5e93\u3002<\/li>\n<li><strong>C \u8bed\u8a00\u6269\u5c55\uff1a<\/strong>\u9700\u8981 C \u8bed\u8a00\u7684\u77e5\u8bc6\u548c\u5bf9 PHP \u6e90\u4ee3\u7801\u7684\u7406\u89e3\uff0c\u96be\u5ea6\u53ef\u80fd\u66f4\u9ad8\u3002<\/li>\n<\/ul>\n<p><strong>\u53ef\u7528\u6027<\/strong><\/p>\n<ul>\n<li><strong>PHP \u51fd\u6570\u6269\u5c55\uff1a<\/strong>\u901a\u5e38\u6bd4 C \u8bed\u8a00\u6269\u5c55\u66f4\u5bb9\u6613\u83b7\u5f97\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u4ee5\u4ece PHP \u5b98\u65b9\u6269\u5c55\u4ed3\u5e93\uff08PECL\uff09\u4e2d\u4e0b\u8f7d\u3002<\/li>\n<li><strong>C \u8bed\u8a00\u6269\u5c55\uff1a<\/strong>\u9700\u8981\u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\u6216\u4ece\u7b2c\u4e09\u65b9\u4f9b\u5e94\u5546\u5904\u83b7\u5f97\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>PHP \u51fd\u6570\u6269\u5c55\uff1a<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a PHP \u51fd\u6570\u6269\u5c55\nfunction my_func() {\n  echo \"Hello from PHP extension!\\n\";\n}\n\n\/\/ \u7f16\u8bd1\u6269\u5c55\n$cmd = 'phpize &amp;&amp; .\/configure &amp;&amp; make &amp;&amp; sudo make install';\nexec($cmd);\n\n\/\/ \u52a0\u8f7d\u6269\u5c55\nextension_load('my_func.so');\n\n\/\/ \u8c03\u7528\u6269\u5c55\u51fd\u6570\nmy_func();<\/pre>\n<p><strong>C \u8bed\u8a00\u6269\u5c55\uff1a<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a C \u8bed\u8a00\u6269\u5c55\n#include &lt;php.h&gt;\n\nPHP_FUNCTION(my_func) {\n  php_printf(\"Hello from C extension!\\n\");\n}\n\n\/\/ \u6ce8\u518c\u6269\u5c55\u51fd\u6570\nzend_function_entry my_functions[] = {\n  PHP_FE(my_func, NULL)\n};\n\n\/\/ \u521d\u59cb\u5316\u6269\u5c55\nPHP_MINIT_FUNCTION(my_extension) {\n  zend_register_functions(my_functions, sizeof(my_functions) \/ sizeof(zend_function_entry));\n  return SUCCESS;\n}<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>PHP \u51fd\u6570\u6269\u5c55\u548c C \u8bed\u8a00\u6269\u5c55\u90fd\u662f\u6269\u5c55 PHP \u529f\u80fd\u7684\u6709\u7528\u5de5\u5177\u3002PHP \u51fd\u6570\u6269\u5c55\u5bb9\u6613\u7f16\u5199\uff0c\u4f46\u6027\u80fd\u8f83\u4f4e\uff0c\u800c C \u8bed\u8a00\u6269\u5c55\u6027\u80fd\u66f4\u9ad8\uff0c\u4f46\u7f16\u5199\u8d77\u6765\u53ef\u80fd\u66f4\u56f0\u96be\u3002\u6839\u636e\u5177\u4f53\u7528\u4f8b\u548c\u6027\u80fd\u9700\u6c42\uff0c\u9009\u62e9\u6700\u5408\u9002\u7684\u6269\u5c55\u7c7b\u578b\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u6709\u4ec0\u4e48\u533a\u522b\uff1f \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300aPHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 PHP \u51fd\u6570\u6269\u5c55\u4e0e C \u8bed\u8a00\u6269\u5c55\u7684\u533a\u522b \u7b80\u4ecb PHP \u6269\u5c55\u4f7f\u7a0b\u5e8f\u5458\u80fd\u591f\u901a\u8fc7\u52a0\u8f7d\u52a8\u6001\u94fe\u63a5\u5e93 (DLL) \u6216\u5171\u4eab\u5bf9\u8c61 (SO) \u6765\u6269\u5c55 PHP \u7684\u529f\u80fd\u3002\u8fd9\u4e9b\u6269\u5c55\u53ef\u4ee5\u662f\u51fd\u6570\u6269\u5c55\uff08\u7528 PHP \u7f16\u5199\uff09\u6216 C \u8bed\u8a00\u6269\u5c55\u3002\u672c\u6587\u5c06\u63a2\u8ba8 PHP \u51fd\u6570\u6269\u5c55\u548c C \u8bed\u8a00\u6269\u5c55\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\u3002 \u5b9e\u73b0 PHP \u51fd\u6570\u6269\u5c55\uff1a\u7528 PHP \u7f16\u5199\uff0c\u7136\u540e\u7f16\u8bd1\u6210\u5171\u4eab\u5bf9\u8c61\u3002 C \u8bed\u8a00\u6269\u5c55\uff1a\u7528 C \u8bed\u8a00\u7f16\u5199\uff0c\u7136\u540e\u7f16\u8bd1\u6210 DLL\/SO\u3002 \u6027\u80fd PHP \u51fd\u6570\u6269\u5c55\uff1a\u901a\u5e38\u6bd4 C \u8bed\u8a00\u6269\u5c55\u6027\u80fd\u8f83\u4f4e\uff0c\u56e0\u4e3a PHP \u662f\u89e3\u91ca\u6027\u8bed\u8a00\u3002 C \u8bed\u8a00\u6269\u5c55\uff1a\u6027\u80fd\u66f4\u9ad8\uff0c\u56e0\u4e3a C \u8bed\u8a00\u662f\u7f16\u8bd1\u6027\u8bed\u8a00\u3002 \u7f16\u5199\u96be\u5ea6 PHP \u51fd\u6570\u6269\u5c55\uff1a\u901a\u5e38\u66f4\u5bb9\u6613\u7f16\u5199\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5229\u7528 PHP \u7684\u8bed\u6cd5\u548c\u5e93\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-46750","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46750","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=46750"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46750\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}