Mainly want to use PHP to develop a CTP trading system, the CTP API using C + + write, do not know what tools to communicate, if using TCP services, is not to use C + + to write?
A bit chaotic, no specific ideas, the way Daniel, help, to provide the next ideas and tools oh, anxious to beg!
Reply content:
Mainly want to use PHP to develop a CTP trading system, the CTP API using C + + write, do not know what tools to communicate, if using TCP services, is not to use C + + to write?
A bit chaotic, no specific ideas, the way Daniel, help, to provide the next ideas and tools oh, anxious to beg!
The simple point is that PHP communicates with other language (C + +) APIs.
can use HTTP,TCP to communicate
See if you want to use HTTP or the lower-level TCP, UDP.
HTTP can only use CURL on the PHP side, or use a third-party library Guzzle
.
If TCP or UDP, first consider the complexity of communication between your two services, if you simply send the data and then receive (that is, as the client, C + + that set as the server), can take advantage of PHP stream_socket_client
, document reference: Http://php.net/manual/zh/func ...
Simply connect the code to send and receive data:
$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)
\n";} else { fwrite($fp, pack("s", 666)); while (!feof($fp)) { $recv .= fread($fp, 1024); } fclose($fp);}
Complex points, which need to be serviced, may be considered Swoole
orWorkerman