{"id":505,"date":"2019-10-30T00:13:38","date_gmt":"2019-10-29T16:13:38","guid":{"rendered":"https:\/\/103.249.111.182\/?p=505"},"modified":"2019-10-30T00:13:38","modified_gmt":"2019-10-29T16:13:38","slug":"%e7%ac%94%e8%ae%b0%e7%bf%bb%e8%af%91-%e5%9c%a8windows%e4%b8%8a%e7%bc%96%e8%af%91php%e6%8b%93%e5%b1%95","status":"publish","type":"post","link":"https:\/\/7gugu.com\/index.php\/2019\/10\/30\/%e7%ac%94%e8%ae%b0%e7%bf%bb%e8%af%91-%e5%9c%a8windows%e4%b8%8a%e7%bc%96%e8%af%91php%e6%8b%93%e5%b1%95\/","title":{"rendered":"[\u7b14\u8bb0][\u7ffb\u8bd1] \u5728Windows\u4e0a\u7f16\u8bd1PHP\u62d3\u5c55"},"content":{"rendered":"<ul>\n<li>\u6765\u81ea\u4e8e Benoit Blanchon 20 January 2015<\/li>\n<li>\u8bd1\u8005 7gugu<\/li>\n<li>\u539f\u6587\u7ae0\u94fe\u63a5 https:\/\/blog.benoitblanchon.fr\/build-php-extension-on-windows\/<\/li>\n<\/ul>\n<p>\u6211\u6700\u8fd1\u5c1d\u8bd5\u7f16\u5199\u4e86\u4e00\u4e2aPHP\u62d3\u5c55,\u867d\u7136\u8bf4\u6587\u6863\u4e0a\u6709\u5f88\u8be6\u7ec6\u7684\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u4e0a\u8fdb\u884c\u7f16\u8bd1\u64cd\u4f5c,\u4f46\u662f\u5173\u4e8e\u5728Windows\u5e73\u53f0\u4e0a\u7f16\u8bd1\u7684\u4fe1\u606f\u5c11\u4e4b\u53c8\u5c11\u3002<\/p>\n<p>\u6240\u4ee5\u8fd9\u7bc7\u6587\u7ae0\u5c31\u662f\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e0b,\u5982\u4f55\u4f7f\u7528Visual Studio\u6784\u5efa\u4e00\u4e2aPHP\u62d3\u5c55\u3002<\/p>\n<h1>\u73af\u5883\u8981\u6c42<\/h1>\n<p>\u8fd9\u7bc7\u6307\u5357\u662f\u5047\u8bbe\u5728\u4f60\u5df2\u7ecf\u7f16\u5199\u4e86\u94fe\u63a5\u6240\u793a\u7684\u4e00\u4e2a\u8f93\u51fa&#8221;Hello World&#8221;\u7684PHP\u62d3\u5c55\u3002 <a href=\"http:\/\/devzone.zend.com\/303\/extension-writing-part-i-introduction-to-php-and-zend\/\">here<\/a>\u5e76\u4e14\u4f60\u5df2\u7ecf\u5728Linux\u4e0a\u6210\u529f\u7f16\u8bd1\u4e86\u3002<\/p>\n<p>\u5728Windows\u4e0a\u6784\u5efa\u4f60\u7684PHP\u62d3\u5c55\u524d,\u4f60\u9700\u8981\u5b8c\u6210\u4ee5\u4e0b\u7684\u64cd\u4f5c\u3002<\/p>\n<ol>\n<li>Visual Studio<br \/>\n<strong>(\u8fd9\u91cc\u662f\u4e00\u4e2a\u5751\u70b9,\u8bf7\u786e\u8ba4\u4f60\u7684VS\u7684\u7f16\u8bd1\u5668\u7684\u7248\u672c\u8ddfPHP\u7f16\u8bd1\u65f6\u7684\u7248\u672c\u662f\u4e00\u6837\u7684\u3002\u6bd4\u5982\u8bf4\u5b98\u7f51\u76847.1.33\u662f\u7528\u7684VC14\u3010VS2015\u3011\u7f16\u8bd1\u7684,\u90a3\u4e48\u4f60\u7684\u62d3\u5c55\u4e5f\u8981\u662f\u7528VC14\u7f16\u8bd1\u7684,\u5426\u5219\u662f\u4e0d\u80fd\u5b89\u88c5\u4f60\u7f16\u8bd1\u597d\u7684\u62d3\u5c55\u7684\u3002\u5982\u679c\u4f60\u7528\u7684\u662fVS2017+,\u4f46\u4f60\u6709\u7528\u7684\u662f\u65e7\u7248\u672c\u7684PHP\u73af\u5883\u5199\u7684\u62d3\u5c55,\u90a3\u4e48\u4f60\u5c31\u8981\u624b\u52a8\u7f16\u8bd1PHP\u624d\u80fd\u4f7f\u7528\u4f60\u7f16\u5199\u7684\u62d3\u5c55\u4e86)<\/strong><\/li>\n<li><a href=\"https:\/\/windows.php.net\/download\/\">PHP\u6e90\u4ee3\u7801<\/a> (\u672a\u7f16\u8bd1\u7684PHP\u4ee3\u7801)<\/li>\n<\/ol>\n<p>\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d,\u6211\u5c06\u4f1a\u6309\u4e00\u4e0b\u5217\u8868\u5047\u8bbe:<\/p>\n<ol>\n<li>PHP\u6e90\u7801\u662f\u4f4d\u4e8e<code>C:\\php-src<\/code><\/li>\n<li>\u4f60\u7f16\u5199\u7684&#8221;Hello World&#8221;\u62d3\u5c55\u4f4d\u4e8e<code>C:\\MyPhpExtensions\\hello<\/code><\/li>\n<\/ol>\n<h1>\u5728Windows\u4e0a\u7f16\u8bd1\u62d3\u5c55\u8ddfLinux\u4e0a\u6709\u70b9\u76f8\u4f3c<\/h1>\n<p>\u4f60\u5e94\u8be5\u5df2\u7ecf\u5f88\u719f\u6089\u8fd9\u4e2a\u8fc7\u7a0b,\u4f46\u8fd9\u91cc\u8fd8\u662f\u5217\u51fa\u4e86\u4e00\u4e2a\u6b65\u9aa4\u6e05\u5355\u7ed9\u4f60:<br \/>\n<strong>(\u4ee5\u4e0b\u867d\u7136\u662f\u5728Linux\u4e0a\u6784\u5efa\u7f16\u8bd1\u65f6\u8fd0\u884c\u7684\u4ee3\u7801,\u4f46\u662f\u5728Windows\u4e0a\u5176\u5b9e\u662f\u4e00\u6837\u7684,\u53ea\u662f\u6709\u4e00\u4e9b\u6307\u4ee4\u7684\u540d\u5b57\u548c\u8fd0\u884c\u65b9\u6cd5\u6709\u70b9\u4e0d\u540c\u800c\u5df2)<\/strong><\/p>\n<ol>\n<li>\u5b89\u88c5 <code>php-devel<\/code> \u5305<\/li>\n<li>\u8fd0\u884c <code>phpize<\/code> \u4ece <code>config.m4<\/code>\u4e2d\u751f\u6210<code>configure<\/code> \u811a\u672c .<\/li>\n<li>\u8fd0\u884c <code>.\/configure --enable-hello<\/code> \u751f\u6210 <code>Makefile<\/code><\/li>\n<li>\u8fd0\u884c <code>make<\/code> \u5f00\u59cb\u7f16\u8bd1\u62d3\u5c55<\/li>\n<\/ol>\n<p><strong>(\u4ee5\u4e0b\u662f\u5728Windows\u4e0a\u7f16\u8bd1\u65f6\u8981\u6539\u53d8\u7684\u4e1c\u897f,\u6309\u6b65\u9aa4\u6267\u884c\u5c31\u53ef\u4ee5\u987a\u5229\u751f\u6210\u62d3\u5c55\u4e86)<\/strong><\/p>\n<h1>\u4f7f\u7528 <code>config.w32<\/code> \u66ff\u4ee3 <code>config.m4<\/code><\/h1>\n<p>\u5728Windows\u5e73\u53f0\u4e0a, \u4f7f\u7528<code>config.w32<\/code>\u4ee3\u66ff<code>config.m4<\/code>,\u4f46\u662f\u683c\u5f0f\u4e0a\u8fd8\u662f\u6709\u70b9\u4e0d\u540c\u3002<\/p>\n<p>\u4ece <code>config.m4<\/code> \u8fc1\u79fb\u5230 <code>config.w32<\/code> \u662f\u975e\u5e38\u76f4\u63a5\u7684, \u4f60\u4ec5\u4ec5\u9700\u8981\u7684\u662f\u628aAutomake\u7684\u4ee3\u7801\u8f6c\u6362\u6210JavaScript\u8bed\u6cd5\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50:<\/p>\n<pre><code class=\"\">ARG_ENABLE(\"hello\", \"Hello World support\", \"no\");\nif (PHP_HELLO != \"no\") {\n    EXTENSION(\"hello\", \"php_hello.c\", true);\n}\n<\/code><\/pre>\n<p>\u4e0d\u8981\u5fd8\u8bb0\u628a<code>EXTENSION<\/code>\u7684\u7b2c\u4e09\u53c2\u6570\u8bbe\u7f6e\u6210<code>true<\/code> , \u8fd9\u4e48\u8bbe\u5b9a\u5c31\u4f1a\u9009\u62e9\u751f\u6210\u52a8\u6001\u7f16\u8bd1\u5e93(DLL)\u800c\u4e0d\u662f\u9759\u6001\u7f16\u8bd1\u5230PHP\u4ee3\u7801\u4e2d\u3002<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u77e5\u9053\u66f4\u591a\u5173\u4e8e&#42;.32\u7684\u8bed\u6cd5\u4fe1\u606f,\u4f60\u53ef\u4ee5\u770b\u770b\u522b\u7684\u6587\u4ef6\u5939\u7684&#42;.w32\u6587\u4ef6\u3002<\/p>\n<h1>\u4f7f\u7528 <code>buildconf.bat<\/code> \u4ee3\u66ff <code>phpize<\/code><\/h1>\n<p>\u5728Windows\u5e73\u53f0\u4e0a,\u4f60\u5c06\u4f1a\u4f7f\u7528 <code>buildconf.bat<\/code> \u4ee3\u66ff <code>phpize<\/code>\u3002<\/p>\n<p>\u6253\u5f00VS\u7684&#8221;\u9002\u7528\u4e8e VS 20XX \u7684 x86\/64 \u672c\u673a\u5de5\u5177\u547d\u4ee4\u63d0\u793a\u201d\u547d\u4ee4\u884c\u5de5\u5177\u5e76\u4e14\u8fd0\u884c\u4ee5\u4e0b\u4ee3\u7801<\/p>\n<pre><code class=\"\">cd C:\\php-src\nbuildconf.bat --add-modules-dir=C:\\MyPhpExtensions\n<\/code><\/pre>\n<p><code>buildconf.bat<\/code> \u5c06\u4f1a\u81ea\u52a8\u626b\u63cf  <code>C:\\MyPhpExtensions<\/code> \u6587\u4ef6\u5939\u4e0b\u6240\u6709\u7684 <code>config.w32<\/code> \u6587\u4ef6\u3002<\/p>\n<p>\u968f\u540e\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a <code>configure.bat<\/code>\u7684\u811a\u672c\u6587\u4ef6.<\/p>\n<h1>\u4f7f\u7528 <code>configure.bat<\/code> \u4ee3\u66ff <code>.\/configure<\/code><\/h1>\n<p>\u5728Linux\u4e0a,<code>configure<\/code>\u5c31\u4ec5\u4ec5\u662f\u7528\u6765\u7f16\u8bd1\u62d3\u5c55\u7528\u7684,\u4f46\u662f\u5728Windows\u5e73\u53f0\u4e0a<code>configure.bat<\/code>\u662f\u7528\u6765\u7f16\u8bd1PHP\u4ee3\u7801\u4e3aexe\u6587\u4ef6\u7684\u3002<\/p>\n<p>\u4f60\u9700\u8981\u5728\u8fd0\u884c <code>configure.bat<\/code> \u65f6\u6dfb\u52a0\u4ee5\u4e0b\u547d\u4ee4\u884c\u9009\u9879\u4ee5\u751f\u6210\u6700\u5c11\u6570\u91cf\u7684\u5185\u5bb9\uff0c\u4ece\u800c\u786e\u4fdd\u4e0d\u5fc5\u89e3\u51b3\u5bf9\u5916\u90e8\u5e93\u7684\u4f9d\u8d56\u6027<\/p>\n<pre><code class=\"\">cd C:\\php-src\nconfigure.bat --disable-all --enable-cli --enable-hello\n<\/code><\/pre>\n<p><code>--disable-all<\/code> \u5c31\u662f\u7981\u6b62\u751f\u6210\u5176\u4ed6\u5185\u5bb9,\u7701\u7565\u4e86\u8f93\u5165 <code>--disable-xxx<\/code> \u548c <code>--without-xxx<\/code>\u7684\u5fc5\u8981 , <code>--enable-cli<\/code> \u662f\u542f\u7528php\u547d\u4ee4\u884c\u754c\u9762 (ie <code>php.exe<\/code>) , <code>--enable-hello<\/code> \u662f\u542f\u7528\u7f16\u8bd1\u4f60\u7684\u62d3\u5c55&#8221;Hello&#8221;<\/p>\n<p>\u7cfb\u7edf\u9ed8\u8ba4\u4f1a\u6309\u7167TS(\u7ebf\u7a0b\u5b89\u5168)\u6a21\u5f0f\u8fdb\u884c\u7f16\u8bd1,\u5982\u679c\u4f60\u9700\u8981NTS(\u7ebf\u7a0b\u975e\u5b89\u5168)\u6a21\u5f0f\u8fdb\u884c\u7f16\u8bd1,\u4f60\u4ec5\u4ec5\u9700\u8981\u52a0\u4e0a\u8fd9\u4e00\u6761 <code>--disable-zts<\/code> ,\u5c31\u53ef\u4ee5\u6309\u7167NTS\u6a21\u5f0f\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n<h1>\u4f7f\u7528 <code>NMake<\/code> \u4ee3\u66ff <code>Make<\/code><\/h1>\n<p><code>configure.bat<\/code> \u5c06\u4f1a\u751f\u6210\u4e00\u4e2aWindows\u7248\u672c\u7684 <code>Makefile<\/code> \u7528\u4f5c\u5728Windows\u4e0a <code>Make<\/code>.(\u7f16\u8bd1\u4ee3\u7801)<\/p>\n<p>\u5f00\u59cb\u7f16\u8bd1\u4ee3\u7801,\u4ec5\u4ec5\u9700\u8981\u8fd0\u884c\u4ee5\u4e0b\u4ee3\u7801\u5373\u53ef:<\/p>\n<pre><code class=\"\">nmake\n<\/code><\/pre>\n<p>\u8fd9\u4e0d\u4ec5\u4ec5\u4f1a\u7f16\u8bd1\u4f60\u81ea\u5df1\u7684\u62d3\u5c55,\u540c\u65f6\u4e5f\u4f1a\u5c06 <code>php.exe<\/code> \u7f16\u8bd1\u51fa\u6765\u3002 \u8fd9\u5bf9\u4e8e\u5f00\u53d1\u8005\u6765\u8bf4,\u662f\u4e00\u4e2a\u5f88\u65b9\u4fbf\u7684\u505a\u6cd5,\u56e0\u4e3a\u4f60\u9700\u8981\u4e00\u4e2a\u76f8\u540c\u7f16\u8bd1\u73af\u5883\u751f\u6210\u51fa\u6765\u7684 <code>php.exe<\/code>,\u90a3\u6837\u5b50\u624d\u80fd\u6b63\u786e\u5b89\u88c5\u4f60\u7684PHP\u62d3\u5c55\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a,\u4e3a\u4e86\u52a0\u8f7d\u5230php\u4e2d,\u60a8\u7684\u6269\u5c55\u5fc5\u987b\u4e0ephp\u6784\u5efa\u76f8\u5339\u914d,\u6761\u4ef6\u662f\uff1a<\/p>\n<ol>\n<li>\u7cfb\u7edf\u4f4d\u6570 (32 or 64 \u4f4d)<\/li>\n<li>\u7ebf\u7a0b\u662f\u5426\u5b89\u5168 (TS \u6a21\u5f0f \u6216\u8005 NTS \u6a21\u5f0f)<\/li>\n<li>\u7f16\u8bd1\u5668\u7684\u7248\u672c (VS9, VS11 \u4e4b\u7c7b\u7684.)<\/li>\n<\/ol>\n<p>\u5982\u679c\u4f60\u786e\u5b9e\u4e0d\u9700\u8981\u7f16\u8bd1\u51fa <code>php.exe<\/code>, \u90a3\u4e48\u4f60\u4ec5\u4ec5\u9700\u8981\u6309\u4ee5\u4e0b\u4ee3\u7801\u8fd0\u884c\u5373\u53ef:<\/p>\n<pre><code class=\"\">nmake php_hello.dll\n<\/code><\/pre>\n<h1>\u6d88\u9664\u8b66\u544a(Warnings)<\/h1>\n<p>\u5728\u7f16\u8bd1PHP\u62d3\u5c55\u7684\u8fc7\u7a0b\u4e2d,\u7f16\u8bd1\u5668\u5e38\u5e38\u4f1a\u62a5\u4e00\u5806\u8b66\u544a:<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u7981\u7528\u8fd9\u4e9b\u8b66\u544a,\u4f60\u53ef\u4ee5\u5728 <code>c:\\php-src\\win32\\build\\config.w32<\/code>\u4e2d,\u52a0\u5165\u4ee5\u4e0b\u7684\u4ee3\u7801\u6bb5:<\/p>\n<pre><code class=\"\">ADD_FLAG('CFLAGS', ' \/wd4005 \/wd4267 \/wd4244 ');\nADD_FLAG('CFLAGS_BD_ZEND', ' \/wd4018 \/wd4101 \/wd4090 \/wd4273 ');\nADD_FLAG('CFLAGS_BD_MAIN', ' \/wd4018 \/wd4090 ');\nADD_FLAG('CFLAGS_BD_MAIN_STREAMS', ' \/wd4013 ');\nDEFINE('RC', '$(RC) \/nologo \/d _USING_V110_SDK71_');\n<\/code><\/pre>\n<p>\u5e76\u4e14,\u5728 <code>C:\\php-src\\ext\\standard\\config.w32<\/code>\u4e2d\u52a0\u5165\u8fd9\u884c\u4ee3\u7801:<\/p>\n<pre><code class=\"\">ADD_FLAG('CFLAGS_BD_EXT_STANDARD', ' \/wd4047 \/wd4018 ');\n<\/code><\/pre>\n<p>\u6700\u540e\u5728 <code>C:\\php-src\\sapi\\cli\\config.w32<\/code>\u4e2d\u52a0\u5165\u4e0b\u5217\u8fd9\u4e00\u884c\u4ee3\u7801:<\/p>\n<pre><code class=\"\">ADD_FLAG('CFLAGS_BD_SAPI_CLI', ' \/wd4018 ');\n<\/code><\/pre>\n<h1>\u7b14\u8bb0: \u4e00\u4e9b\u80fd\u591f\u5e2e\u52a9\u4f60\u5f00\u53d1PHP\u62d3\u5c55\u7684\u535a\u6587[\u82f1\u6587\u751f\u8089]<\/h1>\n<ul>\n<li><a href=\"http:\/\/devzone.zend.com\/303\/extension-writing-part-i-introduction-to-php-and-zend\/\">Extension Writing Part I: Introduction to PHP and Zend<\/a><\/li>\n<li><a href=\"http:\/\/devzone.zend.com\/317\/extension-writing-part-ii-parameters-arrays-and-zvals\/\">Extension Writing Part II: Parameters, Arrays, and ZVALs<\/a><\/li>\n<li>[Extension Writing Part II: Parameters, Arrays, and ZVALs <a href=\"http:\/\/devzone.zend.com\/318\/extension-writing-part-ii-parameters-arrays-and-zvals-continued\/\">continued&#93;<\/a><\/li>\n<li><a href=\"http:\/\/devzone.zend.com\/446\/extension-writing-part-iii-resources\/\">Extension Writing Part III: Resources<\/a><\/li>\n<li><a href=\"http:\/\/devzone.zend.com\/1435\/wrapping-c-classes-in-a-php-extension\/\">Wrapping C++ Classes in a PHP Extension<\/a><\/li>\n<li><a href=\"http:\/\/somabo.de\/talks\/200903_montreal_php_extension_writing.pdf\">PHP Extension Writing<\/a><\/li>\n<li><a href=\"http:\/\/www.kchodorow.com\/blog\/2011\/08\/11\/php-extensions-made-eldrich-php-variables\/\">PHP Extensions Made Eldrich: Working with the API \u00d4\u00c7\u00f4 the PHP C API<\/a><\/li>\n<li><a href=\"http:\/\/www.kchodorow.com\/blog\/2011\/08\/11\/php-extensions-made-eldrich-classes\/\">PHP Extensions Made Eldrich: Classes<\/a><\/li>\n<li><a href=\"https:\/\/wiki.php.net\/internals\/windows\/stepbystepbuild\">Build your own PHP on Windows<\/a><\/li>\n<li><a href=\"http:\/\/www.phpinternalsbook.com\/index.html\">PHP Internals Book<\/a><\/li>\n<li><a href=\"https:\/\/php.net\/manual\/en\/internals2.ze1.zendapi.php\">Zend API: Hacking the Core of PHP<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u81ea\u4e8e Benoit Blanchon 20 January 2015 \u8bd1\u8005 7gugu \u539f\u6587\u7ae0\u94fe\u63a5 http &hellip; <a href=\"https:\/\/7gugu.com\/index.php\/2019\/10\/30\/%e7%ac%94%e8%ae%b0%e7%bf%bb%e8%af%91-%e5%9c%a8windows%e4%b8%8a%e7%bc%96%e8%af%91php%e6%8b%93%e5%b1%95\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c[\u7b14\u8bb0][\u7ffb\u8bd1] \u5728Windows\u4e0a\u7f16\u8bd1PHP\u62d3\u5c55\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,29,3,13,15],"tags":[],"class_list":["post-505","post","type-post","status-publish","format-standard","hentry","category-php","category-29","category-codetype","category-13","category-15"],"_links":{"self":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/comments?post=505"}],"version-history":[{"count":0,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/505\/revisions"}],"wp:attachment":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/media?parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/categories?post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/tags?post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}