Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/plain;');
- error_reporting(E_ALL ^ E_WARNING);
- set_time_limit(0);
- ob_implicit_flush();
- if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
- throw new Exception('socket_create() failed: '.socket_strerror(socket_last_error())."\n");
- }
- $address = 'localhost';
- $port = 10001;
- if (($ret = socket_bind($sock, $address, $port)) < 0) {
- throw new Exception('socket_bind() failed: '.socket_strerror(socket_last_error())."\n");
- }
- if (($ret = socket_listen($sock, 5)) < 0) {
- throw new Exception('socket_listen() failed: '.socket_strerror(socket_last_error())."\n");
- }
- if (($msgsock = socket_accept($sock)) < 0) {
- throw new Exception('socket_accept() failed: '.socket_strerror(socket_last_error())."\n");
- }
- $buf = "";
- while (($buf = socket_read($msgsock, 1024))) { }
- if (false === $buf) {
- throw new Exception('socket_read() failed: '.socket_strerror(socket_last_error())."\n");
- } else {
- // приняли данные, теперь передаем их мускуль серверу
- if (($sock_mysql = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
- throw new Exception('sock_mysql: socket_create() failed: '.socket_strerror(socket_last_error())."\n");
- }
- $result = socket_connect($sock_mysql, "127.0.0.1", "3306");
- if ($result == false)
- {
- throw new Exception('socket_connect() failed: '.socket_strerror(socket_last_error())."\n");
- }
- socket_write($sock_mysql, $buf, strlen($buf));
- // получили ответ от мускуль сервера
- //$out = socket_read($sock_mysql, 1024);
- $out = "";
- while (($out .= socket_read($sock_mysql, 1024))) { }
- // отправляем обратно клиенту
- socket_write($msgsock, $out, strlen($out));
- socket_close($sock_mysql);
- }
- socket_close($sock);
Add Comment
Please, Sign In to add comment