kraken-php / framework

Asynchronous & Fault-tolerant PHP Framework for Distributed Applications.
http://kraken-php.com
MIT License
1.12k stars 59 forks source link

php kraken server:ping returns a remote ip address when it works #52

Closed neutronstein closed 7 years ago

neutronstein commented 7 years ago

Hi. I'm running into this issue after fresh install. php kraken.server works fine but when I execute php kraken server:ping most of time it times out but when it works it returns a remote ip address. I'm using Kraken 0.3.2 on php 7.0.11

khelle commented 7 years ago

What do you mean by remote IP address? The server ping should return the pinged server ID, so if it does it , then it works as intended. Or do you mean "remote" as the fact that server returns client IP instead ?

neutronstein commented 7 years ago

I have a server running in virtualbox. It has 2 network interfaces, one in host only mode and the second one in nat mode. kraken server:ping try to connect to internet i think. When i disable the network interface which is using nat, everything works fine. If both interfaces are on the command times out or it returns an ip address which is not in my local network. That is what i meant by remote. I get an external public ip address.

khelle commented 7 years ago

The client is designed to be able to work for multiple remote servers. That's why it returns the external IP address of the server and not the one in the local network. This works as itended.

neutronstein commented 7 years ago

Is there a way to specify the server to ping?

khelle commented 7 years ago

Ok, I might written a little wrong before. The concept of one client per multiple servers was how the things were done in v0.2. Right now the Kraken is going in direction of single client and server per project. The server works on top of the project architecture, meaning that server is able to contact all the processes and threads inside of the project. You can treat the server as a remote access point of your application, and nothing more. There is no way to specify the different servers, but you might experiment with the channel.channels configuration options inside of default config files in data/config/Console.

On the other hand if by "server" what you mean is you want to get the IP of specific process or thread working inside your application architecture, then you can add console command that does that using cmd:ping runtime command. To do that, you have to:

  1. Create the new console command, lets say App\Console\Command\PingCommand with this body:
namespace App\Console\Command;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Kraken\Console\Client\Command\Command;

class PingCommand extends Command
{
    protected function config()
    {
        $this
            ->setName('app:ping')
            ->setDescription('Pings container with given alias.')
        ;

        $this->addArgument(
            'alias',
            InputArgument::REQUIRED,
            'Alias of container to be pinged.'
        );
    }

    protected function command(InputInterface $input, OutputInterface $output)
    {
        $alias  = $input->getArgument('alias');

        $cmd  = 'cmd:ping'; // the actual command to be called on container
        $opts = [];

        return $this->informServer($alias, $cmd, $opts);
    }
}
  1. Then go to data/config/Console/Client/config.php and this command to command.models array.
  2. Call the command using syntax:
php kraken app:ping MyContainer

Where MyContainer is an alias for the container to be pinged.

You can read a little more about it in http://kraken-php.com/docs/adding-commands .