{"id":2328,"date":"2023-08-08T18:39:14","date_gmt":"2023-08-08T10:39:14","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=2328"},"modified":"2023-08-08T18:39:14","modified_gmt":"2023-08-08T10:39:14","slug":"php%e6%ba%90%e7%a0%81%e7%94%a8%e4%bb%80%e4%b9%88%e8%bd%af%e4%bb%b6%e7%94%9f%e6%88%90app%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/2328\/","title":{"rendered":"php\u6e90\u7801\u7528\u4ec0\u4e48\u8f6f\u4ef6\u751f\u6210app\uff1f"},"content":{"rendered":"
\u5c06PHP\u6e90\u7801\u8f6c\u6362\u6210APP\u7684\u89e3\u51b3\u65b9\u6848\u662f\u5c06PHP\u5e94\u7528\u7a0b\u5e8f\u4e0e\u5185\u7f6eWeb\u670d\u52a1\u5668\u548c\u6d4f\u89c8\u5668\u7ec4\u4ef6\u4e00\u8d77\u6253\u5305\u3002\u8fd9\u6837\uff0c\u7528\u6237\u53ef\u4ee5\u50cf\u4f7f\u7528\u5e38\u89c4\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\u8fd0\u884c\u4f60\u7684PHP\u5e94\u7528\u3002\u4ee5\u4e0b\u662f\u4e24\u79cd\u6d41\u884c\u7684\u65b9\u6cd5\uff0c\u5206\u522b\u662f\u4f7f\u7528PHP\u684c\u9762\u5de5\u5177\u548cNW.js\u3002<\/p>\n
1. \u4f7f\u7528PHP\u684c\u9762\u5de5\u5177\uff08\u5982 ExeOutput for PHP\uff0cPHP Desktop\uff09\uff1a<\/p>\n
\u8fd9\u7c7b\u5de5<\/p>\n
\u5177\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5c06PHP\u6e90\u7801\u6253\u5305\u6210Windows\u6216\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u7684\u684c\u9762\u5e94\u7528\u3002<\/p>\n \u4ee5ExeOutput for PHP\u4e3a\u4f8b\uff0c\u5b83\u7684\u57fa\u672c\u539f\u7406\u662f\u5c06\u4f60\u7684PHP\u6e90\u7801\u3001\u5185\u7f6e\u7684PHP\u8fd0\u884c\u65f6\u73af\u5883\u3001Web\u670d\u52a1\u5668\uff08\u4f8b\u5982Apache\u6216Nginx\uff09\u548cWeb\u6d4f\u89c8\u5668\u7ec4\u4ef6\uff08\u4f8b\u5982Chromium\uff09\u4e00\u8d77\u6253\u5305\u3002\u7528\u6237\u53ea\u9700\u8981\u8fd0\u884c\u751f\u6210\u7684.exe\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u5728\u672c\u5730\u73af\u5883\u4e2d\u4f7f\u7528\u4f60\u7684PHP\u5e94\u7528\u3002<\/p>\n \u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n 1. \u4e0b\u8f7d\u5e76\u5b89\u88c5ExeOutput for PHP\u3002<\/p>\n 2. \u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\uff0c\u5e76\u5c06\u4f60\u7684PHP\u6e90\u7801\u6dfb\u52a0\u5230\u9879\u76ee\u4e2d\u3002<\/p>\n 3. \u914d\u7f6e\u9879\u76ee\u8bbe\u7f6e\uff0c\u4f8b\u5982\u7f51\u7ad9\u9996\u9875\u3001\u7a97\u53e3\u5927\u5c0f\u3001\u5e94\u7528\u56fe\u6807\u7b49\u3002<\/p>\n 4. \u70b9\u51fb\u7f16\u8bd1\u6309\u94ae\uff0c\u751f\u6210.exe\u6587\u4ef6\u3002<\/p>\n 2. \u4f7f\u7528NW.js \u6253\u5305PHP\u5e94\u7528\uff1a<\/p>\n NW.js\u662f\u4e00\u79cd\u5f00\u53d1\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u6280\u672f\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528HTML, CSS, JavaScript\u7b49Web\u6280\u672f\u7f16\u5199GUI\u5e94\u7528\u3002\u4e3a\u4e86\u5c06PHP\u6e90\u7801\u6253\u5305\u6210APP\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6eNW.js\u73af\u5883\uff0c\u4ee5\u4fbf\u4e0e\u5185\u7f6e\u7684Web\u670d\u52a1\u5668\u4e00\u8d77\u5de5\u4f5c\u3002<\/p>\n \u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n 1. \u4e0b\u8f7d\u5e76\u5b89\u88c5NW.js\u3002<\/p>\n 2. \u5728\u4f60\u7684PHP\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a”package\u600e\u4e48\u7ed9app\u4e0b\u8f7d\u751f\u6210\u7f51\u7ad9<\/a>.json”\u7684\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n “`<\/p>\n {<\/p>\n “name”: “your_app_name”,<\/p>\n “main”: “http:\/\/localhost:8000”,<\/p>\n “version”: “1.0.0”,<\/p>\n “window”: {<\/p>\n “title”: “Your App”,<\/p>\n “icon”: “icon.png”<\/p>\n },<\/p>\n “nodejs”: true<\/p>\n }<\/p>\n “`<\/p>\n 3. \u5728PHP\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a”start.js”\u7684\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n “`<\/p>\n const {spawn} = require(‘child_process’);<\/p>\n const phpServer = spawn(‘php’, [‘-S’, ‘localhost:8000’]);<\/p>\n phpServer.stdout.on(‘data’, data => {<\/p>\n console.log(`stdout: ${data}`);<\/p>\n });<\/p>\n phpServer.stderr.on(‘data’, data => {<\/p>\n console.log(`stderr: ${data}`);<\/p>\n });<\/p>\n<\/figure>\n<\/p>\n