Example #1
0
     mostrarDecadas();
     break;
 case 'mostrarCaratula':
     mostrarCaratula($_GET['query']);
     break;
 case 'obtenerXAreas':
     obtenerArea($_GET['id']);
     break;
 case 'mostrarCaratulaScroll':
     mostrarCaratulaScroll($_GET['codigo'], $_GET['howMany'], $_GET['offset']);
     break;
 case 'getDecada':
     getDecada($_GET['decada']);
     break;
 case 'firstGet':
     firstGet($_GET['codigo'], $_GET['howMany'], $_GET['offset']);
     break;
 case 'getIndice':
     getIndice($_GET['decada']);
     break;
 case 'verUsuarios':
     obtener_datosUsuarios();
     break;
 case 'obtenerUsuario':
     obtener_usuario($_GET['name']);
     break;
 case 'agregarUsuario':
     agregar_datosUsuario();
     break;
 case 'actualizarUsuario':
     actualizar_usuario();
<?php

$pos = $_GET['pos'];
//pos是文件索引位置
if (0 == $pos) {
    echo json_encode(firstGet(50));
} else {
    echo json_encode(getAll($pos));
}
function getLogPath()
{
    return '/var/lib/floodlight/floodlight.log';
}
function firstGet($limit = 50)
{
    $logPath = getLogPath();
    if (!$logPath) {
        echo "There is no log!";
        exit;
    }
    if (file_exists($logPath)) {
        $fp = fopen($logPath, 'r');
        fseek($fp, 0, SEEK_END);
        $end_pos = ftell($fp);
        $pos = -2;
        $t = ' ';
        for ($i = 0; $i < $limit; $i++) {
            while ("\n" != $t) {
                fseek($fp, $pos, SEEK_END);
                $t = fgetc($fp);
                if (null == $t) {