{"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

<\/figure>\n<\/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

phpServer.on(‘close’, \u5728\u7ebf\u751f\u6210app\u542f\u52a8\u56fe<\/a>code => {<\/p>\n

console.log(`PHP server process exited with code ${code}`);<\/p>\n

});<\/p>\n

nw.Window.open(‘package.json’, {}, function(win) {});<\/p>\n

“`<\/p>\n

4. \u8fd0\u884c\u547d\u4ee4 “nw .” (\u4e0d\u5e26\u5f15\u53f7)\u542f\u52a8\u5e94\u7528\u3002<\/p>\n

5. \u4f7f\u7528NW.js\u7684\u547d\u4ee4\u884c\u5de5\u5177\u5c06\u9879\u76ee\u6253\u5305\u6210Windows, macOS\u6216Linux\u5e94\u7528\u3002<\/p>\n

\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5c06PHP\u6e90\u7801\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f46\u8bf7\u6ce8\u610f\uff0c\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u4e0d\u9002\u5408\u7528\u4f5c\u5927\u578bWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u66ff\u4ee3\u65b9\u6848\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u7684PHP\u9879\u76ee\u5305\u542b\u5927\u91cf\u7684\u590d\u6742\u529f\u80fd\u6216\u9700\u8981\u4e0e\u8fdc\u7a0b\u670d\u52a1\u5668\u8fdb\u884c\u5b9e\u65f6\u901a\u4fe1\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u80fd\u4e0d\u662f\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"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<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[4887,12,1536,4759,23],"topic":[],"class_list":{"0":"post-2328","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appkf","7":"tag-app","8":"tag-12","9":"tag-1536","11":"tag-23"},"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=2328"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2328\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=2328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=2328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=2328"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=2328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}