Check-in [7ed70e3c6c]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added webservice implementation using APC
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:7ed70e3c6c66712c3fa1b4d4fe54e69ef136f167
User & Date: densch 2015-04-17 02:18:50
Context
2015-04-17
02:34
Added htpasswd file for basic http authentication check-in: a15ea2d674 user: densch tags: trunk
02:18
Added webservice implementation using APC check-in: 7ed70e3c6c user: densch tags: trunk
01:05
Added detection code from MobileESP check-in: 7a3f2c574d user: densch tags: trunk
Changes

Added rcmobiesp/webservice/MobileESPWebservice.inc.

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/*
 * Webservice for MobileESP
 */


require('../mdetect.php');


class MobileESPWebservice {

    private $results;

    function __construct() {
        $methods_array = explode('|', $_GET['methods']);

        $mdetect = new uagent_info();

        try {
            foreach ($methods_array as $method) {
                if (!method_exists($mdetect, $method)) {
                    throw new Exception("No method called " . $method);
                }
                $this->results[$method] = call_user_func(array($mdetect, $method));
            }
        } catch (Exception $e) {
                echo $e->getMessage() . "\n";
        }
    }

    /**
     * @return JSON representation of results
     */
    function toJSON() {
        return json_encode($this->results);
    }

}

?>

Added rcmobiesp/webservice/clear.php.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
<?php
/**
 * Useful for development. APC works only in older versions of PHP.
 */

echo "APC clear cache: " . apc_clear_cache("user") ? "Ok" : "Failure";
?>

Added rcmobiesp/webservice/index.php.























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

$time_start = microtime(true);

function log_msg($message) {
    date_default_timezone_set('UTC');
    $fd = fopen(dirname(__FILE__) . '/logs/redirect.log', 'a');

    if ($fd) {
        fwrite($fd, '[' . date(DATE_RFC822) . '] ' . $message . ' (' . $_SERVER['HTTP_USER_AGENT'] . ")\n");
        fclose($fd);
    }
}

header("Content-Type: application/json");

if (!preg_match('/^(Detect[A-Za-z]+\|*)+$/', $_GET['methods'])) {
    exit(json_encode(array('Error'=> 'No valid methods specified')));
}

$user = $_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT'] . $_GET['methods'];

if (apc_exists($user)) {
    $r = apc_fetch($user);
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    log_msg("cached result: $r took $time seconds");
} else {
    require('MobileESPWebservice.inc');

    $main = new MobileESPWebservice();
    if ($main) {
        $r = $main->toJSON();
    }
    apc_add($user, $r);
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    log_msg("new result: $r took $time seconds");
}

echo $r;

?>