php - IIS Express Hangs with Curl Request -



php - IIS Express Hangs with Curl Request -

i developing website php 5.4 using visual studio 2013, xdebug, , iis express. whenever effort curl request localhost:port, page hangs until the curl request fails due timeout. however, after curl timeout occurs, rest of code on requesting page executes, , code on requested page executes, not help me need info page.

here script makes curl request:

$logfh = fopen("c:\windows\temp\curl_log.log", 'a+'); $ch = curl_init(); curl_setopt($ch,curlopt_url,'http://localhost:46746/test.php'); curl_setopt($ch,curlopt_returntransfer, true); curl_setopt($ch, curlopt_cookie, "xdebug_session=" . $_cookie['xdebug_session'] . ';'); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_timeout,5); curl_setopt($ch,curlopt_verbose , true); curl_setopt($ch,curlopt_stderr ,$logfh ); $result = curl_exec($ch); curl_close($ch); fclose($logfh);

here script on requested page:

<?php echo 'reached test'; ?>

here log of curl request:

adding handle: conn: 0x370ea80 * adding handle: send: 0 * adding handle: recv: 0 * curl_addhandletopipeline: length: 1 * - conn 3 (0x370ea80) send_pipe: 1, recv_pipe: 0 * connect() localhost port 46746 (#3) * trying 127.0.0.1... * connected localhost (127.0.0.1) port 46746 (#3) > /test.php http/1.1 host: localhost:46746 accept: */* cookie: xdebug_session=a53cf524; operation timed out after 5991 milliseconds 0 out of -1 bytes received * closing connection 3

my curl syntax should correct, since can info url. php not show errors. should doing differently?

these 2 options true/false:

curl_setopt($ch,curlopt_verbose , $logfh ); curl_setopt($ch, curlopt_file, $logfh);

update

there few things can assist in finding problem

the curlopt_connecttimeout , curlopt_failonerror of import when debugging. without timeout not timeout , not see results.

i see if server responded @ , http response header may have relevant information, utilize curlopt_header

use curl_getinfo($ch); results.

check curl response errors: curl_errno($ch))

curlinfo_header_out homecoming request header may reveal problem request e.g cookies.

set curlopt_followlocation false in case have recursive redirect.

if not need cookies, don't utilize them, remove them while debugging.

this header no echoed output interpreted html.

header('content-type: text/plain; charset=utf-8'); $ch = curl_init($url); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_header, true); curl_setopt($ch, curlopt_followlocation, false); curl_setopt($ch, curlopt_filetime, true); curl_setopt($ch, curlinfo_header_out,true); curl_setopt($ch, curlopt_connecttimeout, 5); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch, curlopt_autoreferer, true); curl_setopt($ch, curlopt_cookiefile, "testcookies.txt"); curl_setopt($ch, curlopt_timeout,5); curl_setopt($ch, curlopt_cookiejar, "testcookies.txt"); curl_setopt($ch, curlopt_failonerror,true); $data = curl_exec($ch); $info = curl_getinfo($ch); $info = var_export($info,true); if (curl_errno($ch)){ $data .= 'retreive base of operations page error: ' . curl_error($ch); } else { $skip = intval(curl_getinfo($ch, curlinfo_header_size)); $responseheader = substr($data,0,$skip); $data= substr($data,$skip); $info = curl_getinfo($ch); $info = var_export($info,true); } echo $responseheader; echo "\n$info"; echo "\n$data";

you may need alter default header.

$request = array(); $request[] = "host: www.example.com"; $request[] = "accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; $request[] = "user-agent: mot-v9mm/00.62 up.browser/6.2.3.4.c.1.123 (gui) mmp/2.0"; $request[] = "accept-language: en-us,en;q=0.5"; $request[] = "connection: keep-alive"; $request[] = "cache-control: no-cache"; $request[] = "pragma: no-cache"; curl_setopt($ch, curlopt_httpheader,$request);

if need post request:

$post = 'key1=value1&key2=value2&key3=value3'; curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $post);

the curl cookie jar problematic. wrote may own cookie routine.

get cookies response header:

$e = 0; while(true){ $s = strpos($head,'set-cookie: ',$e); if (!$s){break;} $s += 12; $e = strpos($head,';',$s); $cookie = substr($head,$s,$e-$s) ; $s = strpos($cookie,'='); $key = substr($cookie,0,$s); $value = substr($cookie,$s); $cookies[$key] = $value; }

create cookies subsequent requests:

$cookie = ''; $show = ''; $head = ''; $delim = ''; foreach ($cookies $k => $v){ $cookie .= "$delim$k$v"; $delim = '; '; }

add cookies request header:

$request = array(); // clear requests previous request. $request[] = $cookies; curl_setopt($ch, curlopt_httpheader,$request);

php curl iis-express

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -