博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FastCGI 协议分析与C语言实现实例
阅读量:4184 次
发布时间:2019-05-26

本文共 1494 字,大约阅读时间需要 4 分钟。

考虑让我的 web server 增加对 PHP 的支持,这就要用到 php 解析器来将客户端请求的 php 文件解析为静态资源,再由我的 web server 将其返回到客户端,php-fpm 就可以来帮我们完成这个工作。可是我的 web server 如何与 php-fpm 通信呢? 接下来就是本文的主角:FastCGI

FastCGI 实现与测试代码

Web Server 项目地址

Description

C language through FastCGI protocol, through php-fpm, php file parsed into html files.

How to use

Preparation:

please make sure you have installed .

Testing environment:CentOS 7

configuration file:/usr/local/php/etc/php-fpm.conf

php file:my own user home directory —/home/Tanswer/index.php

If you want to run, you need to change the php file path of main.c.

  1. Modify the configuration

    After the installation is complete, the default communication method for unix local domain socket communication, our example and php-fpm for TCP communication, so we should change the configuration, the ip address is set to 127.0.0.1, listening port 9000. As follows:

    enter image description here

  2. restart php-fpm

    sudo service php-fpm restart

  3. compiling and running

    git clone git@github.com:Tanswer/FastCGI.gitcd FastCGI && make./main

    found an error after running:

    error:Unable to open primary script: /home/Tanswer/index.php (No such file or directory)

    This is the issue of permissions, the permissions of index.php are:

    -rw-r--r-- 1 Tanswer Tanswer 64 12月 23 13:16 index.php. From the above default configuration file can be seen, the account that started the php-fpm process is www, and here we change it to Tanswer,as follows:

    enter image description here

    run again ./main, the result is as follows:

    enter image description here

Reference material

博主着重关心如何使用,对协议的细节描述的不是很清楚,请自行查询相关资料。

转载地址:http://zquoi.baihongyu.com/

你可能感兴趣的文章
nginx优化——包括https、keepalive等
查看>>
记一次压力测试和对nginx/tomcat配置的调整
查看>>
第二章 HttpClient 连接管理
查看>>
tcpdump抓包分析TCP三次握手过程
查看>>
tcpdump过滤某个端口
查看>>
TCP协议中FLAG的含义
查看>>
详解 Tomcat 的连接数与线程池
查看>>
tomcat中server.xml配置详解
查看>>
tomcat架构分析(概览)
查看>>
构分析(connector BIO 实现)
查看>>
Java并发之AQS详解
查看>>
Thread类的使用
查看>>
java如何处理中断
查看>>
Java8内存模型—永久代(PermGen)和元空间(Metaspace)
查看>>
Java并发编程:并发容器之CopyOnWriteArrayList(转载)
查看>>
清晰理解红黑树的演变---红黑的含义
查看>>
图解堆排序
查看>>
Mysql有两种存储引擎:InnoDB与Myisam
查看>>
Synchronized与三种锁态
查看>>
Java内部锁(synchronized)中类锁和对象锁
查看>>