Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use ipc from apache (Pipeline) #63

Closed
jonathan-rodan opened this issue Aug 2, 2012 · 2 comments
Closed

Can't use ipc from apache (Pipeline) #63

jonathan-rodan opened this issue Aug 2, 2012 · 2 comments

Comments

@jonathan-rodan
Copy link

Very simple script. (NOTE, the function getRandomString just creates a random string, its not important)

The sender.php:

<?php

function getRandomString($valid_chars, $length) {
     // start with an empty random string
    $random_string = "";

    // count the number of chars in the valid chars string so we know how many choices we have
    $num_valid_chars = strlen($valid_chars);

    // repeat the steps until we've created a string of the right length
    for ($i = 0; $i < $length; $i++) {
         // pick a random number from 1 up to the number of valid chars
         $random_pick = mt_rand(1, $num_valid_chars);

        // take the random character out of the string of valid chars
        // subtract 1 from $random_pick because strings are indexed starting at 0, and we started picking at 1
        $random_char = $valid_chars[$random_pick-1];

        // add the randomly-chosen char onto the end of our string so far
        $random_string .= $random_char;
    }

    // return our finished random string
    return $random_string;
}

$type = ZMQ::SOCKET_PUSH;
$p1 = ($_SERVER['argv'])?'cli':'web').'->'.getRandomString(isset($_SERVER['argv'])?'cli':'web'), 25);
$p2 = getRandomString('qwertyuiopasdfghjklzxcvbnm,1234567890', 500);
$context = new ZMQContext();
$socket = new ZMQSocket($context, $type)
$socket->connect(ipc://mytest.ipc);

$success = $socket->send($p1, ZMQ::MODE_SNDMORE);
$success &= $socket->send('', ZMQ::MODE_SNDMORE);
$success &= $socket->send($p2);

echo $success ? 'YAY  :)' : 'FAIL :(';

receiver.php

<?php
$type = ZMQ::SOCKET_PUSH;
$context = new ZMQContext();
$socket = new ZMQSocket($context, $type)
$socket->bind(ipc://mytest.ipc);
while(true){
    echo $socket->recv();
    echo $socket->recv();
    echo '->msg('.strlen($socket->recv()).')';
}

How to test.

run the receiver.php on the console.

run the sender.php on the console (you will see "YAY")
look at the receiver and it will have: "cli->lciciclciclliclccilcilcil(500)"

open the sender using apache (you will see "YAY" on the browser)
look at the receiver and it will have: "cli->lciciclciclliclccilcilcil(500)" //NOTHING WILL BE RECEIVED
^^^^ERROR^^^^

modify the scripts to use tcp (bind to tcp://*:5555 and connect to tcp://localhost:5555)

(repeat test)

run the receiver.php on the console.

run the sender.php on the console (you will see "YAY")
look at the receiver and it will have: "cli->lciciclciclliclccilcilcil(500)"

open the sender using apache (you will see "YAY" on the browser)
look at the receiver and it will have: "web->wbeebwbebwbebbewbbwewebwb(500)"

@jonathan-rodan
Copy link
Author

Mi mistake, apache and cli use a different folder to create the "file" that's used for the connection.
to solve use the absolute path. (in this case it can be "ipc:///tmp/mytest.ipc")

@SegFaulty
Copy link

thanks for posting the solution jonathan-rodan!
this made my day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants