简体   繁体   English

混合使用Node.js和PHP?

[英]Mix Node.js and PHP?

Could be possible to generate a page with PHP and then run Node.js to apply some edits to it? 可以使用PHP生成页面,然后运行Node.js对其进行一些编辑吗?

On Google I've found examples of PHP and Node.js integration but they are always two different files which work together with Ajax or similar things. 在Google上,我找到了PHP和Node.js集成的示例 ,但它们始终是两个不同的文件,可与Ajax或类似的东西一起使用。

My goal instead is to run Node.js (or something which can run javascript) in this way: 相反,我的目标是以这种方式运行Node.js(或可以运行javascript的东西):

$html = "<html>
            <body>PHP
                <script>document.body.innerHTML = \"Javascript\";</script>
            </body>
         </html>";

$html = run_js($html);

Is it possible? 可能吗?

No. Do not do this. 不。不要这样做。 It may be possible, but it's a really bad idea. 可能有可能,但这是一个非常糟糕的主意。 Pick a single technology stack for your project and stick to it. 为您的项目选择一个技术堆栈并坚持下去。

Splitting you project over multiple technology stacks does nothing of any value (whatever you're wanting Node to do could be done in PHP, and vice-versa), so all it really does is add a massive amount of complexity without achieving anything. 将项目拆分到多个技术堆栈上并没有任何价值(无论您想要Node做什么,都可以用PHP完成,反之亦然),因此,它真正要做的只是增加了大量的复杂性而没有实现任何事情。

If you're going to even think about adding this kind of complexity to your system, you need to understand the implications: This will kill your performance; 如果您甚至打算考虑将这种复杂性添加到系统中,则需要了解其含义:这将损害性能; it will create a maintenance and debugging nightmare; 它将造成维护和调试的噩梦; it will probably introduce weird, hard-to-find bugs. 它可能会引入奇怪的,难以发现的错误。

In short, I really, really advise you not to do this. 简而言之,我真的非常建议您不要这样做。

If you want to use Node.js, that's fine; 如果您想使用Node.js,那很好。 use it. 用它。 But don't mix it into a PHP system; 但是请不要将其混入PHP系统中。 start a new project from scratch. 从头开始一个新项目。

If you really really have to do this you can use PHP V8js. 如果确实需要这样做,则可以使用PHP V8js。 The built-in javascript engine that PHP comes with. PHP附带的内置javascript引擎。 PHP V8js . PHP V8js I agree however with the other answer that this should be avoided as much as possible. 但是,我同意另一个答案,即应尽可能避免这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM