linux上使用strace查看C语言级别的php源码【一种方法】
发布日期:2021-06-30 19:32:22 浏览次数:3 分类:技术文章

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

如果你希望看到C语言级别的php代码就需要使用strace

这个默认是安装了的,如果没有安装可以

#yum install strace

 

查看httpd进程

#ps auxw | grep httpd

有多个,必须停止apache

[root@localhost usr]# /usr/local/webserver/apache2/bin/apachectl stop

 

启动单进程httpd

[root@localhost usr]# /usr/local/webserver/apache2/bin/apachectl -X -k start

 

再使用#ps auxw | grep httpd查看只有单经常,记下进程id

将strace绑定至apache

#strace -p 28224

算法

快速排序php代码

'; print_r(quickSort($arr)); ?>

在浏览器请求php页面,得到追踪信息

注意:如果看C语言生成的文件直接strace即可

#strace ./a.out

如果你只要看php的opcode可以参考:

最简单的php代码

$a='123';   

echo $a;

追踪输出:

我们清晰的看到完整的解析流程

从eAccelerator中去读取缓存:

调用open()函数打开文件-->flock()函数锁定文件-->read()函数读取文件内容-->flock()解除锁定-->close()关闭文件

writev()输出http协议头http/1.1  200等等

关于eAccelerator参考 

----------------------------------------------------

flock() 函数 锁定文件或解除锁定

定义:
int flock(int fd,int operation);
表头文件:
#include<sys/file.h>
说明:
flock()会依参数operation所指定的方式对参数fd所指的文件做各种锁定或解除锁定的动作。此函数只能锁定整个文件, 无法锁定文件的某一区域。
参数:
operation有下列四种情况:
LOCK_SH 建立共享锁定。多个进程可同时对同一个文件作共享锁定。
LOCK_EX 建立互斥锁定。一个文件同时只有一个互斥锁定。
LOCK_UN 解除文件锁定状态。
LOCK_NB 无法建立锁定时, 此操作可不被阻断, 马上返回进程。通常与LOCK_SH或LOCK_EX 做OR(|)组合。
单一文件无法同时建立共享锁定和互斥锁定, 而当使用dup()或fork()时文件描述词不会继承此种锁定。
返回值:
返回0表示成功, 若有错误则返回-1, 错误代码存于errno。
----------------------------------------------------------
静态HTML
我们请求一个html静态文件,追踪信息
可见直接是open()函数去读静态文件
==============================
                
linux函数分析查询工具
1.优先推荐linux 中man命令
2.一个不错的中文Linux手册:
3.在线查英文Man手册:

==============================

通用函数

gettimeofday取得目前的时间

定义:
int gettimeofday ( struct timeval * tv , struct timezone * tz )
表头文件:
#include <sys/time.h>
#include <unistd.h>

gettimeofday()会把目前的时间有tv所指的结构返回, 当地时区的信息则放到tz所指的结构中。

timeval结构定义为:
struct timeval{
long tv_sec; /*秒*/
long tv_usec; /*微秒*/
};
timezone 结构定义为:
struct timezone{
int tz_minuteswest; /*和Greenwich 时间差了多少分钟*/
int tz_dsttime; /*日光节约时间的状态*/
};

#include
#include
main(){ struct timeval tv; struct timezone tz; gettimeofday (&tv , &tz); printf("tv_sec; %d\n", tv,.tv_sec) ; printf("tv_usec; %d\n",tv.tv_usec); printf("tz_minuteswest; %d\n", tz.tz_minuteswest); printf("tz_dsttime, %d\n",tz.tz_dsttime);}
tv_sec: 974857339
tv_usec:136996
tz_minuteswest:-540
tz_dsttime:0

=======================================================================

poll 函数

http://linux.about.com/library/cmd/blcmdl2_poll.htm

Linux / Unix Command: poll

NAME

poll - wait for some event on a file descriptor

SYNOPSIS

#include <sys/poll.h>

int poll(struct pollfd *ufds, unsigned int nfds, int timeout);

DESCRIPTION

pollis a variation on the theme of
select. It specifies an array of
nfdsstructures of type
struct pollfd {                int fd;           /* file descriptor */                short events;     /* requested events */                short revents;    /* returned events */        };
-------------------------

write 将数据写入已打开的文件内

定义:
ssize_t write (int fd,const void * buf,size_t count);
表头文件:
#include<unistd.h>
说明:
write()会把参数buf所指的内存写入count个字节到参数fd所指的文件内。当然, 文件读写位置也会随之移动。
------------------------------

Linux / Unix Command: writev

http://linux.about.com/library/cmd/blcmdl2_writev.htm

NAME

readv, writev - read or write a vector

SYNOPSIS

#include <sys/uio.h>

ssize_t readv(int fd, const struct iovec *vector, int count);

ssize_t writev(int fd, const struct iovec *vector, int count);

struct iovec {    void *iov_base;    /* Starting address */    size_t iov_len;    /* Length in bytes  */};
----------------------------

使用man命令查getsockname

其他函数:

取得用户标识
获取当前目录
检查和改变信号动作,sigaction() 系统调用被用于更改一个进程在接收一个特定信号后的动作。
获取设置定时器的值
在文件描述符上等待事件
获取文件状态
改变工作目录

转载地址:https://linuxstyle.blog.csdn.net/article/details/8195119 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ACCEPT()和ACCEPT4()
下一篇:PHP新的垃圾回收机制:Zend GC详解

发表评论

最新留言

不错!
[***.144.177.141]2024年04月24日 20时51分59秒