note 108431 added to function.file-get-contents
| From: | dustinatdumontprojectdotcom-spamsux | Date: | Wed, 25 Apr 2012 21:25:25 +0000 |
| Subject: | note 108431 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187346@lists.php.net to get a copy of this message | ||
For those who use file_get_contents for JSON or other RESTful services - like my architecture did
for a big site - this will probably help a lot.
We struggled with having the site using get urls that would go through our load balancer instead of
hitting the local server.
What we did was load this function through a local url and set the Host: header for our virtualhost
entries on the site we wanted to laod.
This code solved our issue:
<?php
//set the header context stream for virtualhost lookup
$context = stream_context_create(array('http' => array('header' =>
'Host: www.VIRTUALHOSTDOMAIN.com')));
//use a localhost url or alternatively 127.0.0.1 ip
$url = 'http://localhost/rest-service/?get-user&id=######';
//fetch the data through webserver using the Host http header we set
$data = json_decode(file_get_contents($url, 0, $context));
//verify you have your data
var_dump($data);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 205.147.11.148
----
Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php
Edit -- https://master.php.net/note/edit/108431
Del: integrated -- https://master.php.net/note/delete/108431/integrated
Del: useless -- https://master.php.net/note/delete/108431/useless
Del: bad code -- https://master.php.net/note/delete/108431/bad+code
Del: spam -- https://master.php.net/note/delete/108431/spam
Del: non-english -- https://master.php.net/note/delete/108431/non-english
Del: in docs -- https://master.php.net/note/delete/108431/in+docs
Del: other reasons-- https://master.php.net/note/delete/108431
Reject -- https://master.php.net/note/reject/108431
Search -- https://master.php.net/manage/user-notes.php