【问题标题】:MT4 - Mysql connection via PHPMT4 - 通过 PHP 连接 Mysql
【发布时间】:2013-12-16 17:21:21
【问题描述】:

我需要从/向 Mysql 数据库获取/发送来自 MT4 的数据。我用了“libmysql.dll”或者mysql_wrapper(也是基于libmysql.dll的),但是好像不太稳定。

我想我可以使用 PHP 作为服务器(在指定端口创建 TCP/IP 套接字)和 MT4 EA/脚本作为客户端。 或者也许使用 Apache 作为服务器(创建 PHP 脚本来完成 Mysql 连接的工作)和 MT4 EA/脚本作为客户端。

所以,PHP 是 MT4 和 Mysql 之间的桥梁。 PHP 从 MT4 获取请求,连接到 Mysql(并根据需要进行计算),然后将结果发送回 MT4。 您能否告诉我如何在 Windows XP 中执行此操作(我的 Windows XP 上安装了 Apache、PHP、Mysql)?

谢谢 杰克

【问题讨论】:

    标签: php mysql sockets tcp-ip mt4


    【解决方案1】:

    我得到了这个打开特定端口并等待连接的 PHP 脚本。我可以使用 Telnet 连接到它。任何人都知道如何使用 MQL4 连接到该端口?

    谢谢

    // usage example in command prompt: telnet 192.168.7.21  168168 
    // To quit, type: quit 
    // To shutdown PHP server, type: shutdown // //
    // **************************************************************
    
    
    <?php error_reporting(E_ALL);
    
    /* Allow the script to hang around waiting for connections. */ set_time_limit(0);
    
    /* Turn on implicit output flushing so we see what we're getting  * as it comes in. */ ob_implicit_flush();
    
    $address = '192.168.7.21'; $port = 168168;
    
    if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
        echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; }
    
    if (socket_bind($sock, $address, $port) === false) {
        echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; }
    
    if (socket_listen($sock, 5) === false) {
        echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; }
    
    do {
        if (($msgsock = socket_accept($sock)) === false) {
            echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
            break;
        }
        /* Send instructions. */
        $msg = "\nWelcome to the PHP Test Server. \n" .
            "To quit, type 'quit'. To shut down the server type 'shutdown'.\n";
        socket_write($msgsock, $msg, strlen($msg));
    
        do {
            if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
                echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
                break 2;
            }
            if (!$buf = trim($buf)) {
                continue;
            }
            if ($buf == 'quit') {
                break;
            }
            if ($buf == 'shutdown') {
                socket_close($msgsock);
                break 2;
            }
            $talkback = "PHP server: You said '$buf'.\n";
            socket_write($msgsock, $talkback, strlen($talkback));
            echo "$buf\n";
        } while (true);
        socket_close($msgsock); } while (true);
    
    socket_close($sock); ?>
    

    【讨论】:

      【解决方案2】:

      如果我去你那里,我就不会那样...

      也许你应该看看消息队列(AMQP - RabbitMQ - ZeroMQ)...

      看到那个帖子http://worldwide-invest.org/threads/34585-Messaging-queue-AMQP-(RabbitMQ-ZeroMQ)-and-MT4

      您将看到我可以使用任何语言收集刻度数据并将它们存储在支持 RabbitMQ 的语言支持的任何数据库中(很多从 Python 到 Java,通过 C、C++、C# ...)。

      Metatrader 和 ZeroMQ (ZMQ) 之间也有一座桥梁 https://github.com/AustenConrad/mql4zmq

      【讨论】:

        【解决方案3】:

        首先,我假设您正在尝试将 MT4 客户端(不是服务器)连接到 MySQL 数据库。否则,没有理由存在稳定性问题。如果您使用 EA 连接到数据库,请小心处理连接,EA 不是标准可执行文件,EA 内的代码在每个“tick”上运行,因此请考虑到这一点。相信我,将 PhP 放在中间只会让事情变得复杂,因为它们是如此简单(并且会显着降低性能!)。如果我们可以提供任何帮助,请告诉我们:www.mt4software.com

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-12-30
          • 2010-12-24
          • 2013-08-06
          • 2019-02-06
          • 2010-12-02
          • 2018-09-15
          • 1970-01-01
          相关资源
          最近更新 更多