c语言 协议分析,FastCGI 协议分析与C语言实现实例

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

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 php-fpm.

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.

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:

6738048d38399f8fe39ddd4bbfe53729.png

restart php-fpm

sudo service php-fpm restart

compiling and running git clone git@github.com:Tanswer/FastCGI.git

cd 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:

596f3b4ea98f2664ea64f0a0ca4e90f6.png

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

75317726a0088c733969e17b3a62d1ec.png

Reference material

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值