Skip to content
Advertisement

Run function in another thread

So say there are two running codes: script1 and script2. I want script2 to be able to run a function in script1. script1 will be some kind of background process that will run “forever”.

The point is to be able to make an API for a background process, E.G. a server.

The unclean way to do it would be to have a file transmit the orders from script2. script1 would then execute it with exec(). However, I would like to use a module or something cleaner because then I would be able to output classes and not only text.

EDIT: example:

script1:

JavaScript

script2:

JavaScript

The execution would look like this:

  1. Run script1
  2. Run script2 in a parallel window

Advertisement

Answer

Summary

The XMLRPC modules are designed for this purpose.

The docs include a worked out example for a server (script1) and a client (script2).

Server Example

JavaScript

Client Example

JavaScript
Advertisement