How to open connect to external server on start of WebSocket server?
I have a PHP based Websocket server that is used to connect web clients. The WebSocket server itself serving as a _Client_ for WhatsApp. I want when server goes up, it then make a call to WhatsApp and make a live connection. Below is my WebSocket Class. Since there's an infinite `While` loop, other things are not being called; like connecting a client.

**How do I make it that when Web Socket server loads up, it makes a connection to WhatsApp server as well and then let other clients to connect Web Socket server**

**Chat.php**

```
#!/usr/local/bin/php
<?php

ini_set('display_errors',1);
error_reporting(E_ALL);
require_once __DIR__.'/vendor/autoload.php';
require_once 'vendor/whatsapp/chat-api/src/whatsprot.class.php';
require_once 'vendor/whatsapp/chat-api/src/events/MyEvents.php';
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

use Guzzle\Http\Client;
use Guzzle\Http\EntityBody;
use Guzzle\Http\Message\Request;
use Guzzle\Http\Message\Response;



class Chat implements MessageComponentInterface {
      protected $clients;
      protected $message;
      protected $client_info = []; //To hold which agent was connected
      protected $username = 'xx';
      protected $password = 'xx=';
      protected $nickname = 'xx Number';
      protected $target = "xx";
      protected $debug = false;

    public function __construct() {
        $this->clients = new \SplObjectStorage;
        print("..Server is coming up..\n");

        echo "[] Logging in as '$this->nickname' ($this->username)\n";
        $w = new WhatsProt($this->username, $this->nickname, $this->debug,true,__DIR__.'/wadata/');
        $events = new MyEvents($w);
        $events->setEventsToListenFor($events->activeEvents);
        $w->connect();
        $w->loginWithPassword($this->password);
        print("..Accepting WhatsApp Messages...\n");
        while (1) {
            $w->pollMessage();
        }
    }

    public function onOpen(ConnectionInterface $conn) {
        // Store the new connection to send messages to later
        $this->clients->attach($conn);
        //Identity Message
        $this->message = json_encode(['STATUS'=> 'CONNECTED','CLIENT_ID' => $conn->resourceId]);
        $conn->send($this->message);
        $this->message = json_encode(['STATUS' => 'NEW', 'TYPE'=> 'TEXT','MESSAGE' => "This is by customer"]);
        //Actual WhatsApp message
        $conn->send($this->message);

        echo "New connection! ({$conn->resourceId})\n";
    }

    public function onMessage(ConnectionInterface $from, $msg) {
        $numRecv = count($this->clients) - 1;
        print("CLIENT SAYS:- ".$msg."\n");

        foreach ($this->clients as $client) {
            if ($from === $client) {
                $msg = 'WA Server responds:- '.$msg;
                $client->send($this->message);
            }
        }
    }

    public function onClose(ConnectionInterface $conn) {
        // The connection is closed, remove it, as we can no longer send it messages
        $this->clients->detach($conn);

        echo "Connection {$conn->resourceId} has disconnected\n";
    }

    public function onError(ConnectionInterface $conn, \Exception $e) {
        echo "An error has occurred: {$e->getMessage()}\n";

        $conn->close();
    }
}

$server = IoServer::factory(
    new HttpServer(
        new WsServer(
            new Chat()
        )
    ),
    8080
);
$server->run();
```
