硬件平台:RK1109/T31/RK3308

软件系统:Linux,Lighttpd/ Nginx, FCGI, HTML/JS

《嵌入式系统的WEB开发》-LMLPHP

选择使用FCGI,除了使用C 开发调用系统资源方便外. FCGI 可以解决CGI 多入口的问题,统一的入口,对数据同步,都是比较方便。实现简单的WEB 后台总共需要3步:

一、配置Lighttpd.conf 和fastcgi.conf

server.modules += ( "mod_fastcgi" )
fastcgi.debug=2                                                            
fastcgi.server = (  
                  "/api/v1/gw/" =>(
                  "main" => ("host" => "127.0.0.1", "port" => 2048, "bin-path" =>                         "/var/www/fcgiMain",  
                  "check-local" => "disable",
                  "max-procs" => 1,   //多服务处理
                      )  
                )
)

二、fcgiMain 主程序处理入口,FCGI 入口,Lighttpd 将http请求

static void *doit(void *a)
{
    int rc, i, thread_id = (int)a;
    FCGX_InitRequest(&request, 0, 0);
    while(g_bRunning)
    {
        rc = FCGX_Accept_r(&request);
        if (rc < 0)
        {
            usleep(1000);
            continue;
        }
        method =  FCGX_GetParam("REQUEST_METHOD", request.envp);
        //TODO... 业务处理
        FCGX_Finish_r(&request);
    }
    return NULL;
}
 

三、前端实现和调用FCGI接口 HTML/JS

<body>
        <form method=GET action="fcgiMain">
            <div>
                <input type="submit" name="cmd" value="restore" >
            </div>
        </form >
 </body>

04-27 15:42