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!
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>
If it’s more complicated and needs to build a server, you can consider Swoole
or Workerman