日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

linux上使用strace查看C语言级别的php源码【一种方法】

發布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux上使用strace查看C语言级别的php源码【一种方法】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如果你希望看到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代碼

<?phpfunction quickSort($arr){$len    = count($arr);if($len <= 1) {return $arr;}$key = $arr[0];$left_arr    = array();$right_arr    = array();for($i=1; $i<$len; $i++){if($arr[$i] <= $key){$left_arr[] = $arr[$i];} else {$right_arr[] = $arr[$i];}}$left_arr    = quickSort($left_arr);$right_arr    = quickSort($right_arr);return array_merge($left_arr, array($key), $right_arr);}$arr = array(6,3,8,5,9,2,10);echo '<pre>';print_r(quickSort($arr));?>


在瀏覽器請求php頁面,得到追蹤信息


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

#strace ./a.out


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

PHP安裝與使用VLD查看opcode代碼【一種方法】


最簡單的php代碼

$a='123';? ?
echo $a;


追蹤輸出:


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

從eAccelerator中去讀取緩存:

調用open()函數打開文件-->flock()函數鎖定文件-->read()函數讀取文件內容-->flock()解除鎖定-->close()關閉文件

writev()輸出http協議頭http/1.1? 200等等

關于eAccelerator參考 PHP安裝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手冊:http://cpp.ezbty.org/manpage

3.在線查英文Man手冊:

http://www.kernel.org/doc/man-pages/

http://man7.org/linux/man-pages/dir_all_alphabetic.html



http://linux.about.com/od/commands/l/blcmdl.htm

http://linux.die.net/man/

http://www.linuxmanpages.com/

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

通用函數

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<sys/time.h>
#include<unistd.h>
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


其他函數:

ACCEPT()和ACCEPT4()

getuid  取得用戶標識
getcwd  獲取當前目錄
rt_sigaction(2)  檢查和改變信號動作,sigaction() 系統調用被用于更改一個進程在接收一個特定信號后的動作。
setitimer  獲取設置定時器的值
poll(2) 在文件描述符上等待事件
stat64 獲取文件狀態
chdir  改變工作目錄


總結

以上是生活随笔為你收集整理的linux上使用strace查看C语言级别的php源码【一种方法】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。