最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Docker, PHP and stream_socket_client: connection timeout - Stack Overflow

programmeradmin1浏览0评论

I built a PHP application to establish a TCP socket connection to a mail server (SMTP server) on port 25, using a proxy. Here the main part:

$context = [
    "http" => [
        "proxy" => "tcp://xx.xx.xx.xx:xxxx",
        "request_fulluri" => true 
        "header" => "Proxy-Authorization: Basic xxxxxxxxxxx"
    ]]
};

$connection = @stream_socket_client(
        address: "tcp://$mxHost:25",
        error_code: $errno,
        error_message: $errstr,
        timeout: 10,
        context: $context
);

I built the first version of the app as a Vanilla PHP with some Symfony components, and I run it using php -S localhost:8000 -t . and it works like a charm.

Then I decided to install Symfony, inside a Docker installation. Since I build a DDD/Clean Architecture application, it was easy to switch to a fully Symfony application.

But then the problems start.

It seems like inside Docker I cannot use stream_socket_client correctly, I always get a connection timeout (110).

At some point I added

    dns:  # Custom DNS settings
      - 8.8.8.8
      - 1.1.1.1

to my docker-compose.yml, and it worked for one day. The day after, it stopped to works and I started again to get connection timeout.

My knowledge about network is not so strong, so I need a help.

Can someone give me a tip, a suggestion, an idea to unblock this situation?

发布评论

评论列表(0)

  1. 暂无评论