php 模擬併發請求 PHP介面併發測試的方法

2021-10-22 21:15:46 字數 608 閱讀 8825

php介面併發測試的方法

header(『content-type:text/html; charset=utf-8『);

$uri = "輸入你的url";

$data = array(

『test『=>1

$ch = curl_init();

// print_r($ch);

curl_setopt($ch, curlopt_url, $uri);

curl_setopt($ch, curlopt_post, 1);

curl_setopt($ch, curlopt_header, 0);

curl_setopt($ch, curlopt_returntransfer, 1);

curl_setopt($ch, curlopt_postfields, $data);

$return = curl_exec($ch);

curl_close($ch);

然後用ab小工具測試

鍵入命令:

ab -n 800 -c 800

(-n發出800個請求,-c模擬800併發,相當800人同時訪問,後面是測試url 一般用本地測試就行了)

php併發請求

一般在php進行請求url的時候,直接用 fopen 函式就可以搞定了,比如像這樣 file fopen r or exit ret while feof file fclose file echo ret 當然,也可以直接用 socket 方式,自己定義好http頭引數手動實現 但這些請求方式都是...

php請求介面

php模擬post傳送請求,呼叫引數 方法 function request post url param posturl url curlpost param ch curl init 初始化curl curl setopt ch,curlopt url,posturl 抓取指定網頁 curl s...

php模擬post提交請求,呼叫介面

模擬post進行url請求 param string url param string param function request post url param posturl url curlpost param ch curl init 初始化curl curl setopt ch,curlo...