예제 #1
0
function do_request()
{
    global $port;
    $client = stream_socket_client("tcp://127.0.0.1:{$port}", $errno, $errstr, 1.0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
    if ($client === FALSE) {
        echo "Failed to connect to server {$errstr}\n";
    }
    echo "Sending request to server...\n";
    if (fwrite($client, "ping", 4) == 0) {
        echo "Failed writing to socket.\n";
    }
    $data = read_all_data($client, 4);
    if ($data === false) {
        return false;
    }
    echo "Client received response: {$data}\n";
    return true;
}
예제 #2
0
                $data_result = insert_data();
                break;
            case 2:
                $data_result = update_data();
                break;
            case 3:
                $data_result = delete_data();
                break;
            case 4:
                $data_result = read_data();
                break;
            case 5:
                $data_result = read_all_data();
                break;
            default:
                $data_result = read_all_data();
                break;
        }
    } else {
        $data_result = array("status" => 0, "message" => "Aunthentication failed");
    }
} else {
    $data_result = array("status" => 1, "message" => "Request method not accepted");
}
//CRUD FUNCTIONS
function insert_data()
{
    $name = $_POST['name'];
    $email = $_POST['email'];
    $status = $_POST['status'];
    if (empty($name) || empty($email)) {