MT4 - 通过PHP连接Mysql

时间:2013-11-30 18:21:55

标签: php mysql sockets tcp-ip mt4

我需要从/从Mysql数据库获取/发送数据。我使用“libmysql.dll”或mysql_wrapper(也基于libmysql.dll),但似乎不稳定。

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

因此,PHP是MT4和Linux之间的桥梁。 Mysql的。 PHP从MT4获取请求,连接到Mysql(并在需要时进行计算),然后将结果发送回MT4。 你能否告诉我如何在Windows XP中做到这一点(我在Windows XP上安装了Apache,PHP,Mysql)?

由于 千斤顶

3 个答案:

答案 0 :(得分:0)

我得到了这个打开特定端口并等待连接的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); ?>

答案 1 :(得分:0)

如果我在哪里,我就不会这样......

也许你应该看看消息队列(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

答案 2 :(得分:0)

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