プログラムを検証してみました。
結論として送信先(下記検証プログラムでserver.php)でvar_dumpの出力を扱いたい時は出力をバッファリングしてログに書き込めばできます。
(そもそもvar_dumpせずにそのままログにデータを書き込む方がよいかと思います)
以下簡単な検証プログラムです。
client.php
php -S localhost:9998で起動
<?php
define("API_URL", "http://localhost:9999/server.php");
$data = array("field1" => "aaa", "field2" => "123");
$json_data = json_encode($data);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
);
$curl = curl_init(API_URL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($curl, CURLOPT_COOKIE, $_SERVER['HTTP_COOKIE']);
curl_setopt_array($curl, $options);
$result = curl_exec($curl);
curl_close($curl);
echo $result;
server.php
php -S localhost:9999で起動
<?php
ob_start();
var_dump($_POST);
$result =ob_get_contents();
ob_end_clean();
$fp = fopen("./dump.txt", "a+" );
fputs($fp, $result);
fclose( $fp );
//追記:ローカルサーバーのコンソールに出力
$stdout= fopen( 'php://stdout', 'w' );
fputs( $stdout, json_encode($_POST));
fclose( $stdout );
ブラウザでhttp://localhost:9998/client.phpにアクセスし、client.phpからserver.phpへのcurlでの通信を実行
dump.txtにvar_dump結果の保存を確認
###追記 Guzzleを使ったclient.php
composer.json
{
"require": {
"guzzlehttp/guzzle": "^6.3"
}
}
client.php
<?php
require 'vendor/autoload.php';
$client = new \GuzzleHttp\Client();
$res = $client->request('POST', 'http://localhost:9999/server',[
'form_params' => [
"field1"=>"test"
],
]);
echo $res->getBody();
echo $res->getStatusCode();
- composer installでインストール
- php client.phpで実行
参考までにLaravelでのルータの受け口
Route::post('server', function (\Illuminate\Http\Request $request) {
return $request->input("field1")."a";
});
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/17 10:11
2017/08/17 11:14 編集
2017/08/18 03:21
2017/08/18 03:32
2017/08/18 03:46
2017/08/18 04:00 編集
2017/08/18 05:07
2017/08/18 05:43 編集
2017/08/18 06:11