Home > Backend Development > PHP Tutorial > PHP develops CTP trading system

PHP develops CTP trading system

WBOY
Release: 2023-03-03 08:48:01
Original
1541 people have browsed it

I mainly want to use PHP to develop a CTP trading system. The API of CTP is written in C++. I don’t know what tool to use for communication. If I use tcp service, do I need to write it in C++?
It’s a bit messy and I don’t have any specific ideas. Experts from all over the world can help me and provide me with ideas and tools. Urgent!

Reply content:

I mainly want to use PHP to develop a CTP trading system. The API of CTP is written in C++. I don’t know what tool to use for communication. If I use tcp service, do I need to write it in C++?
It’s a bit messy and I don’t have any specific ideas. Experts from all over the world can help me and provide me with ideas and tools. Urgent!

To put it simply, it is a problem of communication between PHP and other languages ​​(C++) API.
You can use http and tcp to communicate

It depends on whether you want to use HTTP or the lower-level TCP and UDP.

HTTP For PHP, you only need to use cURL, or use a third-party library Guzzle.

If it is TCP or UDP, first consider the complexity of the communication between your two services. If you just simply send data and then receive it (that is, as the client and the C++ one as the server), you can use PHP's stream_socket_client , Document reference: http://php.net/manual/zh/func...

Simply connect the code to send and receive data:

<code class="php">$fp = stream_socket_client("tcp://10.1.7.122:27710", $errno, $errstr, 5);
// UDP 改一下 Schema 就好,如下:
// $fp = stream_socket_client("udp://10.1.7.122:27710", $errno, $errstr, 5);

if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, pack("s", 666));
    while (!feof($fp)) {
        $recv .= fread($fp, 1024);
    }
    fclose($fp);
}</code>
Copy after login

If it’s more complicated and needs to build a server, you can consider Swoole or Workerman

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template