php - url_get_contents working at second attempt -
hoping advice i'm writing here issue:
i have php script uses url_get_contents
execute script , retrieve json domain. both ends under control.
the calling function is:
$this->url_to_call = 'http://example.com/b_controller.php'; $jsondata = array( 'table' => 'countries', 'key' => '44', ); $jsondataencoded = json_encode($jsondata); $post = file_get_contents( $this->url_to_call, null, stream_context_create( array( 'http' => array( 'protocol_version' => 1.1, 'user_agent' => 'mozilla/5.0 (macintosh; intel mac os x 10_8_4) applewebkit/537.36 (khtml, gecko) chrome/27.0.1453.116 safari/537.36', 'method' => 'post', 'header' => "content-type: application/json\r\n"."connection: close\r\n" ."content-length: " . strlen($jsondataencoded) . "\r\n", 'content' => $jsondataencoded, ), ) ) ); $data = json_decode($post, true);
if run code, on first attempt get:
warning: file_get_contents(http://example.com/b_controller.php): failed open stream: error occurred during connection attempt because connected part did not respond after period of time, or there error in established connection because connected host not respond. in
c:\xampp\htdocs\origin_com\a_controller.php
on line 220
but if refresh page or add if( !$data ) $data = $post = file_get_contents( $this->url_to_cal......;
it responds right json.
if leave script 2 minutes , re-run again same error.
i have no clues why happening.
any advice appreciated.
wiki
Comments
Post a Comment