示例#1
0
<?php

class RedeemAPI
{
    // Main method to redeem a code
    function redeem()
    {
        echo "Hello, PHP!";
    }
}
// This is the first thing that gets called when this page is loaded
// Creates a new instance of the RedeemAPI class and calls the redeem method
$api = new RedeemAPI();
$api->redeem();
示例#2
0
<?php

//$address = "";
$address = "192.168.2.13";
$port = 50000;
$fp = fsockopen($address, $port);
if ($fp) {
    // port is open and available
    fclose($fp);
    exit(0);
} else {
    // port is closed or blocked
    include "database.php";
    $api = new RedeemAPI();
    error_reporting(~E_NOTICE);
    set_time_limit(0);
    $max_clients = 20;
    if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
    }
    echo "Socket created \n";
    // Bind the source address
    if (!socket_bind($sock, $address, $port)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not bind socket : [{$errorcode}] {$errormsg} \n");
    }
    echo "Socket bind OK \n";
    if (!socket_listen($sock, 20)) {