0

I know that you can use PHP or node.js server-side, but is it possible to use both PHP and JS together, for example PHP calling a JS function?

My goal is to call JS for the more intensive math functions, but I don't want these to be seen on the clientside. I've tried searching many different sites but it seems my question is pretty specific. Thanks

9
  • 1
    Please read over stackoverflow.com/help/how-to-ask , and its very helpful to attempt stackoverflow.com/help/mcve Commented Nov 3, 2017 at 17:55
  • @Randall: What would an MCVE of this question even look like? The question is quite clear, if a bit broad: Is it possible to call JS server-side from PHP and, if so, how? Commented Nov 3, 2017 at 17:57
  • I was about to answer this by recommending PHP V8js if you really want to do this. Commented Nov 3, 2017 at 17:57
  • Related but not a dupetarget: stackoverflow.com/questions/18760984/mix-node-js-and-php (that question is specifically about generating a "page" in PHP then passing it through JavaScript code to amend the page; this question isn't limited in that way). Commented Nov 3, 2017 at 18:00
  • 1
    @Randall: Many -- most -- questions are code-specific. Not all by any means. Commented Nov 3, 2017 at 18:10

1 Answer 1

2

There are a couple of ways to do this:

  1. Use some kind of bridging technology. The briefest search turned up this one, for instance. Edit: User blues mentions PHP V8js as well.

  2. Have a Node process running and bound only to localhost, and have your PHP code make queries to it (perhaps via HTTP).

Sign up to request clarification or add additional context in comments.

2 Comments

If node was installed on the same server, I guess you wouldn't necessarily need a node http server running. You could just exec node files, right?
@Don'tPanic: Fair point, absolutely. You'd have the cost of spinning up a process, though, which is fairly costly, as opposed to connecting to an existing process. But yes, quite true. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.