# Twitch IRC with PHP Socket

**URL:** <https://discuss.dev.twitch.com/t/twitch-irc-with-php-socket/59702>\
**Category:** Chat and IRC\
**Created:** [July 21, 2024, 9:06am UTC](https://discuss.dev.twitch.com/t/twitch-irc-with-php-socket/59702 "2024-07-21T09:06:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BakerSoftware](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@BakerSoftware](https://discuss.dev.twitch.com/u/BakerSoftware)\
**Post date:** [July 21, 2024, 9:06am UTC](https://discuss.dev.twitch.com/t/twitch-irc-with-php-socket/59702/1 "2024-07-21T09:06:26Z")

</div>

Hiya,

I’m working on creating a Twitch chatbot within PHP and I’ve hit a hurdle with receiving any responses from the Twitch IRC.

As far as I am aware I am connecting successfully with the Twitch IRC server and sending some PASS/NICK commands. However, I’m receiving no data back from the IRC server, not even the MOTD that I should get after PASS/NICK commands.

I am developing this on my local environment using Docker. This app is also a fresh Laravel app.

Below is my workflow to initialise the PHP socket.

```auto
public function connect()
    {
        $tcpConnector = new TcpConnector($this->loop);
        $dnsResolverFactory = new Factory();
        $dns = $dnsResolverFactory->createCached('1.1.1.1', $this->loop);
        $dnsConnector = new DnsConnector($tcpConnector, $dns);
        $connectorPromise = $dnsConnector->connect(sprintf('%s:6667', $this->host));

        $connectorPromise->then(function (ConnectionInterface $connection) {
            $this->socket = $connection;
            $this->isConnected = true;

            Log::info("Connected to the following IRC Server : {$this->socket->getRemoteAddress()}");

            $this->socket->on('data', function ($data) {
                Log::info("[>] $data");
            });

            $this->chatSend('CAP REQ :twitch.tv/membership twitch.tv/tags');
            $this->chatSend("PASS oauth:$this->oAuth");
            $this->chatSend("NICK $this->nick");
        }, function (\Exception $error) {
            Log::info($error);
        });

        $this->loop->run();
    }

```

Here is an example log of this connect function.

```auto
[2024-07-21 09:02:54] local.INFO: Connected to the following IRC Server : 34.212.92.60:6667  
[2024-07-21 09:02:54] local.INFO: [<] CAP REQ :twitch.tv/membership twitch.tv/tags
 (1)  
[2024-07-21 09:02:54] local.INFO: [<] PASS oauth:2xik66orlt3a ******************
 (1)  
[2024-07-21 09:02:54] local.INFO: [<] NICK bakersoftware
 (1)  

```

Any tips/advice would be helpful 🙂

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 21, 2024, 9:20am UTC](https://discuss.dev.twitch.com/t/twitch-irc-with-php-socket/59702/2 "2024-07-21T09:20:11Z")

</div>

Save yourself a bunch of faff and use a library called [SmartIRC](https://pear.php.net/package/Net_SmartIRC)

When I did my bots in php I modified it manually for IRCv3 support. But I don’t think I have a copy of that kicking around. But should be straight forward to apply manually yourself. Just refer to the iirc specification.

---

<div class="post-metadata">

**Author:** ![BakerSoftware](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@BakerSoftware](https://discuss.dev.twitch.com/u/BakerSoftware)\
**Post date:** [July 26, 2024, 6:15pm UTC](https://discuss.dev.twitch.com/t/twitch-irc-with-php-socket/59702/3 "2024-07-26T18:15:30Z")

</div>

Thanks Barry,

Will give that a go

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [August 25, 2024, 6:16pm UTC](https://discuss.dev.twitch.com/t/twitch-irc-with-php-socket/59702/4 "2024-08-25T18:16:09Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
