{"id":47621,"date":"2024-12-02T13:26:00","date_gmt":"2024-12-02T05:26:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47621\/"},"modified":"2024-12-02T13:26:00","modified_gmt":"2024-12-02T05:26:00","slug":"php-%e5%87%bd%e6%95%b0%e4%b8%8e-c-%e6%89%a9%e5%b1%95%e4%ba%a4%e4%ba%92%e7%9a%84%e6%9c%ba%e5%88%b6%e4%b8%8e%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47621\/","title":{"rendered":"PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5<\/h1>\n<p>\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5\u300b<\/span>\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01<\/p>\n<p>PHP \u51fd\u6570\u901a\u8fc7 Zend API \u4e0e C \u6269\u5c55\u4ea4\u4e92\uff0c\u5141\u8bb8 C \u6269\u5c55\u8c03\u7528 PHP \u51fd\u6570\u5e76\u8bbf\u95ee\u5176\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u521b\u5efa C \u6269\u5c55\u6a21\u5757\u3001\u8c03\u7528 Zend API \u51fd\u6570\u3001\u4f20\u9012\u53c2\u6570\u3001\u83b7\u53d6\u8fd4\u56de\u503c\u3001\u7f16\u8bd1\u6269\u5c55\u548c\u542f\u7528\u6269\u5c55\u3002\u4e00\u4e2a\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 greet() \u51fd\u6570\u5411 PHP \u8f93\u51fa\u95ee\u5019\u8bed\uff0c\u6269\u5c55\u4e86 PHP \u7684\u529f\u80fd\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729926278671c94862dc01.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u662f\u4e00\u4e2a\u5907\u53d7\u63a8\u5d07\u7684\u5f00\u6e90 Web \u7f16\u7a0b\u8bed\u8a00\uff0c\u7528\u4e8e\u521b\u5efa\u52a8\u6001\u4e14\u4ea4\u4e92\u5f0f\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u63d0\u4f9b\u4e86\u5185\u7f6e\u51fd\u6570\u3001\u7c7b\u548c\u6269\u5c55\uff0c\u4ee5\u589e\u5f3a\u5176\u529f\u80fd\u548c\u5b9a\u5236\u3002\u4e0e\u5176\u4ed6\u8bed\u8a00\u7c7b\u4f3c\uff0cPHP \u5141\u8bb8\u6211\u4eec\u521b\u5efa\u81ea\u5b9a\u4e49\u6269\u5c55\u4ee5\u8fdb\u4e00\u6b65\u6269\u5c55\u5176\u529f\u80fd\u3002\u8fd9\u4e9b\u6269\u5c55\u53ef\u4ee5\u7528 C \u8bed\u8a00\u7f16\u5199\uff0c\u5e76\u4e0e PHP \u51fd\u6570\u4ea4\u4e92\uff0c\u4ee5\u6267\u884c\u7279\u5b9a\u4efb\u52a1\u6216\u8bbf\u95ee\u5e95\u5c42\u7cfb\u7edf\u8d44\u6e90\u3002<\/p>\n<p><strong>\u4ea4\u4e92\u673a\u5236<\/strong><\/p>\n<p>PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e4b\u95f4\u7684\u4ea4\u4e92\u901a\u8fc7\u540d\u4e3a Zend API \u7684\u4e00\u7ec4\u63a5\u53e3\u5b9e\u73b0\u3002Zend API \u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u51fd\u6570\u548c\u5b8f\uff0c\u4f7f C \u6269\u5c55\u80fd\u591f\u76f4\u63a5\u8c03\u7528 PHP \u51fd\u6570\u5e76\u8bbf\u95ee\u5176\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002<\/p>\n<p><strong>\u5b9e\u8df5\u6307\u5357<\/strong><\/p>\n<p>\u8981\u521b\u5efa\u4e00\u4e2a\u4e0e PHP \u51fd\u6570\u4ea4\u4e92\u7684 C \u6269\u5c55\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u521b\u5efa C \u6269\u5c55\u6a21\u5757\uff1a<\/strong>\u4f7f\u7528 C \u8bed\u8a00\u521b\u5efa\u6269\u5c55\u6a21\u5757\uff0c\u5b9a\u4e49\u6269\u5c55\u51fd\u6570\u7684\u63a5\u53e3\u548c\u5b9e\u73b0\u3002<\/li>\n<li><strong>\u8c03\u7528 Zend API \u51fd\u6570\uff1a<\/strong>\u5728\u6269\u5c55\u51fd\u6570\u7684\u5b9e\u73b0\u4e2d\uff0c\u4f7f\u7528 <code>zend_call_function()<\/code> \u51fd\u6570\u6765\u8c03\u7528 PHP \u51fd\u6570\u3002<\/li>\n<li><strong>\u4f20\u9012\u53c2\u6570\uff1a<\/strong>\u5c06\u53c2\u6570\u4f5c\u4e3a\u6570\u7ec4\u4f20\u9012\u7ed9 <code>zend_call_function()<\/code>\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4e00\u4e2a PHP \u53d8\u91cf\u3002<\/li>\n<li><strong>\u83b7\u53d6\u8fd4\u56de\u503c\uff1a<\/strong>\u901a\u8fc7\u8fd4\u56de\u4e00\u4e2a <code>zval<\/code> \u7ed3\u6784\u4f53\u6765\u83b7\u53d6 PHP \u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002<\/li>\n<li><strong>\u7f16\u8bd1\u6269\u5c55\uff1a<\/strong>\u4f7f\u7528 PHP \u6269\u5c55\u6784\u5efa\u5de5\u5177\uff0c\u4f8b\u5982 <code>phpize<\/code> \u548c <code>make<\/code>\uff0c\u6765\u7f16\u8bd1\u6269\u5c55\u6a21\u5757\u3002<\/li>\n<li><strong>\u542f\u7528\u6269\u5c55\uff1a<\/strong>\u5c06\u7f16\u8bd1\u540e\u7684\u6269\u5c55\u6a21\u5757\u6dfb\u52a0\u5230 PHP \u914d\u7f6e\u4e2d\u5e76\u91cd\u65b0\u542f\u52a8 Web \u670d\u52a1\u5668\u3002<\/li>\n<\/ol>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 C \u6269\u5c55\u793a\u4f8b\uff0c\u5b83\u5b9a\u4e49\u4e86\u4e00\u4e2a <code>greet()<\/code> \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u4f7f\u7528 <code>printf()<\/code> \u51fd\u6570\u5411 PHP \u8f93\u51fa\u4e00\u4e2a\u95ee\u5019\u8bed\uff1a<\/p>\n<pre>PHP_FUNCTION(greet)\n{\n    char *name;\n    size_t name_len;\n\n    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \"s\", &amp;name, &amp;name_len) == FAILURE) {\n        return;\n    }\n\n    printf(\"Hello, %s!\\n\", name);\n}<\/pre>\n<p>\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u8c03\u7528 <code>greet()<\/code> \u51fd\u6570\uff1a<\/p>\n<pre>&lt;?php\n\/\/ \u52a0\u8f7d\u6269\u5c55\ndl('greet.so');\n\n\/\/ \u8c03\u7528\u6269\u5c55\u51fd\u6570\ngreet('John Doe');\n?&gt;<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Hello, John Doe!<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u9075\u5faa Zend API\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e0e PHP \u51fd\u6570\u4ea4\u4e92\u7684 C \u6269\u5c55\uff0c\u4ece\u800c\u6269\u5c55 PHP \u7684\u529f\u80fd\u548c\u5b9a\u5236\u3002\u901a\u8fc7\u5b9e\u6218\u6848\u4f8b\uff0c\u6211\u4eec\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 C \u6269\u5c55\u6784\u5efa\u53ef\u4e0e PHP \u51fd\u6570\u65e0\u7f1d\u4ea4\u4e92\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5 \u4f60\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587\u300aPHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01 PHP \u51fd\u6570\u901a\u8fc7 Zend API \u4e0e C \u6269\u5c55\u4ea4\u4e92\uff0c\u5141\u8bb8 C \u6269\u5c55\u8c03\u7528 PHP \u51fd\u6570\u5e76\u8bbf\u95ee\u5176\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u521b\u5efa C \u6269\u5c55\u6a21\u5757\u3001\u8c03\u7528 Zend API \u51fd\u6570\u3001\u4f20\u9012\u53c2\u6570\u3001\u83b7\u53d6\u8fd4\u56de\u503c\u3001\u7f16\u8bd1\u6269\u5c55\u548c\u542f\u7528\u6269\u5c55\u3002\u4e00\u4e2a\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 greet() \u51fd\u6570\u5411 PHP \u8f93\u51fa\u95ee\u5019\u8bed\uff0c\u6269\u5c55\u4e86 PHP \u7684\u529f\u80fd\u3002 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u673a\u5236\u4e0e\u5b9e\u8df5 \u7b80\u4ecb PHP \u662f\u4e00\u4e2a\u5907\u53d7\u63a8\u5d07\u7684\u5f00\u6e90 Web \u7f16\u7a0b\u8bed\u8a00\uff0c\u7528\u4e8e\u521b\u5efa\u52a8\u6001\u4e14\u4ea4\u4e92\u5f0f\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u63d0\u4f9b\u4e86\u5185\u7f6e\u51fd\u6570\u3001\u7c7b\u548c\u6269\u5c55\uff0c\u4ee5\u589e\u5f3a\u5176\u529f\u80fd\u548c\u5b9a\u5236\u3002\u4e0e\u5176\u4ed6\u8bed\u8a00\u7c7b\u4f3c\uff0cPHP \u5141\u8bb8\u6211\u4eec\u521b\u5efa\u81ea\u5b9a\u4e49\u6269\u5c55\u4ee5\u8fdb\u4e00\u6b65\u6269\u5c55\u5176\u529f\u80fd\u3002\u8fd9\u4e9b\u6269\u5c55\u53ef\u4ee5\u7528 C \u8bed\u8a00\u7f16\u5199\uff0c\u5e76\u4e0e PHP \u51fd\u6570\u4ea4\u4e92\uff0c\u4ee5\u6267\u884c\u7279\u5b9a\u4efb\u52a1\u6216\u8bbf\u95ee\u5e95\u5c42\u7cfb\u7edf\u8d44\u6e90\u3002 \u4ea4\u4e92\u673a\u5236 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e4b\u95f4\u7684\u4ea4\u4e92\u901a\u8fc7\u540d\u4e3a Zend API \u7684\u4e00\u7ec4\u63a5\u53e3\u5b9e\u73b0\u3002Zend API [&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-47621","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47621","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=47621"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47621\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}