1--TEST-- 2swoole_curl/setopt: cURL option CURLOPT_READFUNCTION 3--CREDITS-- 4WHITE new media architects - Jeroen Vermeulen 5#testfest Utrecht 2009 6--SKIPIF-- 7<?php 8require __DIR__ . '/../../include/skipif.inc'; 9skip_unsupported(); 10?> 11--FILE-- 12<?php 13require __DIR__ . '/../../include/bootstrap.php'; 14 15function custom_readfunction($oCurl, $hReadHandle, $iMaxOut) 16{ 17 $sData = fread($hReadHandle,$iMaxOut-10); # -10 to have space to add "custom:" 18 if (!empty($sData)) 19 { 20 $sData = "custom:".$sData; 21 } 22 return $sData; 23} 24 25$sFileBase = dirname(__FILE__).DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION'; 26$sReadFile = $sFileBase.'_in.tmp'; 27$sWriteFile = $sFileBase.'_out.tmp'; 28$sWriteUrl = 'file://'.$sWriteFile; 29 30file_put_contents($sReadFile,'contents of tempfile'); 31$hReadHandle = fopen($sReadFile, 'r'); 32 33$oCurl = curl_init(); 34curl_setopt($oCurl, CURLOPT_URL, $sWriteUrl); 35curl_setopt($oCurl, CURLOPT_UPLOAD, 1); 36curl_setopt($oCurl, CURLOPT_READFUNCTION, "custom_readfunction" ); 37curl_setopt($oCurl, CURLOPT_INFILE, $hReadHandle ); 38curl_exec($oCurl); 39curl_close($oCurl); 40 41fclose ($hReadHandle); 42 43$sOutput = file_get_contents($sWriteFile); 44var_dump($sOutput); 45?> 46===DONE=== 47--CLEAN-- 48<?php 49$sFileBase = dirname(__FILE__).DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION'; 50$sReadFile = $sFileBase.'_in.tmp'; 51$sWriteFile = $sFileBase.'_out.tmp'; 52unlink($sReadFile); 53unlink($sWriteFile); 54?> 55--EXPECT-- 56string(27) "custom:contents of tempfile" 57===DONE=== 58