Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use Thrift to serialize your objects and then use IPC method of your liking(named pipe,message queues etc). The following is a simple example using pipes</p> <ol> <li>We have a an object of type Message which contains some information </li> <li>Php process is the producer of the message</li> <li>Java process is the consumer</li> </ol> <h2>Thrift model</h2> <pre><code>struct Message { 1: i32 uid, 2: string information, } </code></pre> <p>generate thrift sources</p> <pre><code>thrift --gen java message.thrift thrift --gen php message.thrift </code></pre> <h2>PHP producer</h2> <pre><code>&lt;?php $GLOBALS['THRIFT_ROOT'] = 'src'; require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php'; require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinarySerializer.php'; // this generates serialized string from our obect require_once $GLOBALS['THRIFT_ROOT'].'/packages/message/message_types.php'; //from generated thrift sources //create new message $message = new Message(); $message-&gt;uid = '1'; $message-&gt;information = 'Some info'; var_dump($message); //serialize $serializer = new TBinarySerializer(); $serialized_message = $serializer-&gt;serialize($message); var_dump($serialized_message); //write to a pipe if (pcntl_fork() == 0) { $namedPipe = '/tmp/pipe'; if (! file_exists($namedPipe)) { posix_mkfifo($namedPipe, 0600); } $fifo = fopen($namedPipe, 'w'); fwrite($fifo, $serialized_message); exit(0); } ?&gt; </code></pre> <h2>Java Consumer</h2> <pre><code> //read from pipe FileInputStream fileInputStream = new FileInputStream(new File("/tmp/pipe")); int availableBytes = fileInputStream.available(); byte[] b = new byte[availableBytes]; fileInputStream.read(b , 0, availableBytes); //deserialize TDeserializer tDeserializer = new TDeserializer(); Message deserMessage = new Message(); tDeserializer.deserialize(deserMessage, b); System.out.println(deserMessage.getInformation()); //prints "Some info" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload