Reputation: 12163
I have the following code:
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=> "x-api-key: hidden"
)
);
$context = stream_context_create($opts);
$fp = fopen('https://mercury.postlight.com/parser?url=https://www.dev-metal.com/architecture-stackoverflow/', 'r', false, $context);
fpassthru($fp);
fclose($fp);
which outputs the following:
{"title":"The architecture of StackOverflow","author":null,"date_published":"2014-01-11T11:54:47.000Z","dek":null,"lead_image_url":"https://www.dev-metal.com/wp-content/uploads/2014/01/stackoverflow3.jpg","content":"
One of the most interesting talks these weeks, and a rare insight into one of the most active pages on the web: Marco Cecconi of StackOverflow speaks about the general server architecture, why they don’t unit-test (!), how they release (5 times a day) and shows some awesome server load screenshots. It’s fascinating that they run one of the most trafficked pages (that also uses long-polling “real-time” messaging !) on just 25 servers, most of them on 10% load all the time. “We could run it on just 5 servers if needed”. Awesome. Nice statements regarding caching and using existing code, too.
I really like the Get-Things-Done attitude and the simple, but productive view on workflow (use multiple monitors, don’t be the nerd sitting in front of a laptop). The code is not perfect (lots of static methods), they don’t even test, only have a hand full of developers (!) and nearly no downtime. Ah yes, and they run one of the most successful sites in the history of the internet.
“Languages are just tools”. “You’ll be successful anyways, or fail anyways [it does not depend on the language].” I really like that guy. And by the way, they mainly use dot.net for the site. Make sure you also check out the links, especially #5 shows the current tech stack used in the company.
And by the way, have you noticed that EXTREMELY huge presentation screen ? Awesome! They obviously did this in a cinema or university audimax.
Update #1: The slides of this talk:
https://speakerdeck.com/sklivvz/the-architecture-of-stackoverflow-developer-conference-2013
","next_page_url":null,"url":"https://www.dev-metal.com/architecture-stackoverflow/","domain":"www.dev-metal.com","excerpt":"One of the most interesting talks these weeks, and a rare insight into one of the most active pages on the web: Marco Cecconi of StackOverflow speaks about the general server architecture, why they…","word_count":256,"direction":"ltr","total_pages":1,"rendered_pages":1}
My problem is I can't seem to get the array to output to where I can manipulate it. I tried using extract()
and using foreach()
to output but its acting like its a string. But what has me stumped is the fact I can only var_dump()
the output. If someone knows what I am doing wrong please let me know. Only fix I can think of is, if the output is just a string, is there a way to turn it back into an array?
Upvotes: 2
Views: 150
Reputation: 5
Try this
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=> "x-api-key: hidden"
)
);
$context = stream_context_create($opts);
$fp = fopen('https://mercury.postlight.com/parser?url=https://www.dev-metal.com/architecture-stackoverflow/','r',false,$context);
$jsonData = stream_get_contents($fp);
$arrayData = json_decode($jsonData,true);
print_r($arrayData);
Upvotes: 0
Reputation: 334
try using this;
header('x-api-key: hidden');
$str = file_get_contents($url);
$output = json_decode($str, true);
Upvotes: 1
Reputation: 57002
You should read the contents from file and then convert to json
$fp = fopen('https://mercury.postlight.com/parser?url=https://www.dev-metal.com/architecture-stackoverflow/', 'r', false, $context);
$contents = stream_get_contents($fp);
$output = json_decode($contents, true);
print_r($output);
Reference: fread Check Example #3 Remote fread() examples
Upvotes: 2
Reputation: 123
Please try following code :
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=> "x-api-key: hidden"
)
);
$context = stream_context_create($opts);
$fp = fopen('https://mercury.postlight.com/parser?url=https://www.dev-metal.com/architecture-stackoverflow/', 'r', false, $context);
$output = json_decode($fp, true);
print_r($output);
fclose($fp);
Thanks...
Upvotes: 0