Related
I'm trying to get a specific value out of a JSON file in PHP how could this be done. I'm trying to find the value of "allTests": [{"TestOnBlazemeterWasBroken": true}] in the code below and check if it is there and if it equals to true. the value can be true or false and 'TestOnBlazemeterWasBroken' can be also 'TestOnBlazemeterFailed' or 'TestOnBlazemeterWasSuccessful' it depends on the success of an API test
The json file from where i need to find the value "allTests": [{"TestOnBlazemeterWasBroken": true}]
{
"id": "311e6d5a-3f20-42d2-b276-80c5f33f1d7f",
"name": "Testing",
"timestamp": "2021-07-02T10:39:48.544Z",
"collection_id": "6cd6e3b9-cce9-4746-83ca-9349708d3b18",
"folder_id": 0,
"environment_id": "db26e19d-4373-4004-9ad2-348545c6f521",
"totalPass": 1,
"totalFail": 0,
"results": [
{
"id": "bb1b9473-2f66-4153-8996-88cf40715ba6",
"name": "retrieving ID's",
"url": "https://a.blazemeter.com/api/v4/tests?workspaceId=894576&limit=20&hasExecutions=true&filterByActivePlatform=false",
"time": 1116,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
1116
],
"allTests": [
{}
]
},
{
"id": "c694f16e-8195-4696-a874-fdaed51bbfd7",
"name": "Session summary1",
"url": "https://a.blazemeter.com/api/v4/tests/9661550/sessions-summaries",
"time": 259,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
259
],
"allTests": [
{}
]
},
{
"id": "e80d222f-89fe-45cd-a139-6d1b0cfafece",
"name": "Session summary2",
"url": "https://a.blazemeter.com/api/v4/tests/9595495/sessions-summaries",
"time": 442,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
442
],
"allTests": [
{}
]
},
{
"id": "4b129897-0241-465b-94dc-29814808442e",
"name": "Session summary3",
"url": "https://a.blazemeter.com/api/v4/tests/9595540/sessions-summaries",
"time": 319,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
319
],
"allTests": [
{}
]
},
{
"id": "bd17cd20-7165-48e0-8a03-c2d95affc4d1",
"name": "Session summary4",
"url": "https://a.blazemeter.com/api/v4/tests/9595539/sessions-summaries",
"time": 593,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
593
],
"allTests": [
{}
]
},
{
"id": "557c971f-f918-49f1-9d69-7c9547bfe504",
"name": "Session summary5",
"url": "https://a.blazemeter.com/api/v4/tests/9595355/sessions-summaries",
"time": 337,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
337
],
"allTests": [
{}
]
},
{
"id": "8dd94fcc-d04c-43ac-9793-ba0351a41a9d",
"name": "Get master id",
"url": "https://a.blazemeter.com/api/v4/sessions/r-sg-60dc87126dd20190458039",
"time": 259,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
259
],
"allTests": [
{}
]
},
{
"id": "201bd700-de90-45b7-83f6-06b8c7322727",
"name": "See the masters test",
"url": "https://a.blazemeter.com/api/v4/masters/35589479",
"time": 284,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {
"TestOnBlazemeterWasBroken": true
},
"testPassFailCounts": {
"TestOnBlazemeterWasBroken": {
"pass": 1,
"fail": 0
}
},
"times": [
284
],
"allTests": [
{
"TestOnBlazemeterWasBroken": true
}
]
}
],
"count": 1,
"totalTime": 3609,
"collection": {
"requests": [
{
"id": "bb1b9473-2f66-4153-8996-88cf40715ba6",
"method": "GET"
},
{
"id": "c694f16e-8195-4696-a874-fdaed51bbfd7",
"method": "GET"
},
{
"id": "e80d222f-89fe-45cd-a139-6d1b0cfafece",
"method": "GET"
},
{
"id": "4b129897-0241-465b-94dc-29814808442e",
"method": "GET"
},
{
"id": "bd17cd20-7165-48e0-8a03-c2d95affc4d1",
"method": "GET"
},
{
"id": "557c971f-f918-49f1-9d69-7c9547bfe504",
"method": "GET"
},
{
"id": "8dd94fcc-d04c-43ac-9793-ba0351a41a9d",
"method": "GET"
},
{
"id": "201bd700-de90-45b7-83f6-06b8c7322727",
"method": "GET"
}
]
}
}
The part I'm looking for is "allTests": [{"TestOnBlazemeterWasBroken": true}] how could I find this value and check if it is there and if it equals to true.
{
"id": "201bd700-de90-45b7-83f6-06b8c7322727",
"name": "See the masters test",
"url": "https://a.blazemeter.com/api/v4/masters/35589479",
"time": 284,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {
"TestOnBlazemeterWasBroken": true
},
"testPassFailCounts": {
"TestOnBlazemeterWasBroken": {
"pass": 1,
"fail": 0
}
},
"times": [
284
],
"allTests": [
{
"TestOnBlazemeterWasBroken": true
}
]
}
I have tried this but it didn't work - and I get this error:
Fatal error: Uncaught TypeError: Cannot access offset of type string on string in C:\xampp\htdocs\index.php:11 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 11
Code:
<?php
// Read JSON file
$json = file_get_contents('Testing.postman_test_run.json');
//Decode JSON
$json_data = json_decode($json,true);
//Traverse array and get the data for students aged less than 20
foreach ($json_data as $key1 => $value1) {
if($json_data[$key1]["allTests"][7]['TestOnBlazemeterWasBroken'] == true){
print_r($json_data[$key1]);
}
}
?>
The following ought to work OK whether there is one or more results.
$str='{
"id": "311e6d5a-3f20-42d2-b276-80c5f33f1d7f",
"name": "Testing",
"timestamp": "2021-07-02T10:39:48.544Z",
"collection_id": "6cd6e3b9-cce9-4746-83ca-9349708d3b18",
"folder_id": 0,
"environment_id": "db26e19d-4373-4004-9ad2-348545c6f521",
"totalPass": 1,
"totalFail": 0,
"results": [
{
"id": "bb1b9473-2f66-4153-8996-88cf40715ba6",
"name": "retrieving IDs",
"url": "https://a.blazemeter.com/api/v4/tests?workspaceId=894576&limit=20&hasExecutions=true&filterByActivePlatform=false",
"time": 1116,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
1116
],
"allTests": [
{}
]
},
{
"id": "201bd700-de90-45b7-83f6-06b8c7322727",
"name": "See the masters test",
"url": "https://a.blazemeter.com/api/v4/masters/35589479",
"time": 284,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {
"TestOnBlazemeterWasBroken": true
},
"testPassFailCounts": {
"TestOnBlazemeterWasBroken": {
"pass": 1,
"fail": 0
}
},
"times": [
284
],
"allTests": [
{
"TestOnBlazemeterWasBroken": true
}
]
}
]
}';
$fail=false;
$testname='TestOnBlazemeterWasBroken';
$json=json_decode( $str );
$results=$json->results ?: false;
if( $results ){
foreach( $results as $result ){
if( property_exists( $result, 'allTests' ) ){
foreach( $result->allTests as $test ){
if( property_exists( $test, $testname ) && $test->$testname==true ){
$fail=true;
break 2;
}
}
}
}
}
$status=$fail ? 'Failed! ' : 'Passed!';
printf( 'The test "%s" was %s', $testname, $status );
Given the above $str data this will yield "The test "TestOnBlazemeterWasBroken" was Failed!" because within one of the results the specific test was found and evaluated to true.
Given the source data ( saved as blaze-test.json )
{
"id": "311e6d5a-3f20-42d2-b276-80c5f33f1d7f",
"name": "Testing",
"timestamp": "2021-07-02T10:39:48.544Z",
"collection_id": "6cd6e3b9-cce9-4746-83ca-9349708d3b18",
"folder_id": 0,
"environment_id": "db26e19d-4373-4004-9ad2-348545c6f521",
"totalPass": 1,
"totalFail": 0,
"results": [
{
"id": "bb1b9473-2f66-4153-8996-88cf40715ba6",
"name": "retrieving ID's",
"url": "https://a.blazemeter.com/api/v4/tests?workspaceId=894576&limit=20&hasExecutions=true&filterByActivePlatform=false",
"time": 1116,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
1116
],
"allTests": [
{}
]
},
{
"id": "c694f16e-8195-4696-a874-fdaed51bbfd7",
"name": "Session summary1",
"url": "https://a.blazemeter.com/api/v4/tests/9661550/sessions-summaries",
"time": 259,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
259
],
"allTests": [
{}
]
},
{
"id": "e80d222f-89fe-45cd-a139-6d1b0cfafece",
"name": "Session summary2",
"url": "https://a.blazemeter.com/api/v4/tests/9595495/sessions-summaries",
"time": 442,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
442
],
"allTests": [
{}
]
},
{
"id": "4b129897-0241-465b-94dc-29814808442e",
"name": "Session summary3",
"url": "https://a.blazemeter.com/api/v4/tests/9595540/sessions-summaries",
"time": 319,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
319
],
"allTests": [
{}
]
},
{
"id": "bd17cd20-7165-48e0-8a03-c2d95affc4d1",
"name": "Session summary4",
"url": "https://a.blazemeter.com/api/v4/tests/9595539/sessions-summaries",
"time": 593,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
593
],
"allTests": [
{}
]
},
{
"id": "557c971f-f918-49f1-9d69-7c9547bfe504",
"name": "Session summary5",
"url": "https://a.blazemeter.com/api/v4/tests/9595355/sessions-summaries",
"time": 337,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
337
],
"allTests": [
{}
]
},
{
"id": "8dd94fcc-d04c-43ac-9793-ba0351a41a9d",
"name": "Get master id",
"url": "https://a.blazemeter.com/api/v4/sessions/r-sg-60dc87126dd20190458039",
"time": 259,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {},
"testPassFailCounts": {},
"times": [
259
],
"allTests": [
{}
]
},
{
"id": "201bd700-de90-45b7-83f6-06b8c7322727",
"name": "See the masters test",
"url": "https://a.blazemeter.com/api/v4/masters/35589479",
"time": 284,
"responseCode": {
"code": 200,
"name": "OK"
},
"tests": {
"TestOnBlazemeterWasBroken": true
},
"testPassFailCounts": {
"TestOnBlazemeterWasBroken": {
"pass": 1,
"fail": 0
}
},
"times": [
284
],
"allTests": [
{
"TestOnBlazemeterWasBroken": true
}
]
}
],
"count": 1,
"totalTime": 3609,
"collection": {
"requests": [
{
"id": "bb1b9473-2f66-4153-8996-88cf40715ba6",
"method": "GET"
},
{
"id": "c694f16e-8195-4696-a874-fdaed51bbfd7",
"method": "GET"
},
{
"id": "e80d222f-89fe-45cd-a139-6d1b0cfafece",
"method": "GET"
},
{
"id": "4b129897-0241-465b-94dc-29814808442e",
"method": "GET"
},
{
"id": "bd17cd20-7165-48e0-8a03-c2d95affc4d1",
"method": "GET"
},
{
"id": "557c971f-f918-49f1-9d69-7c9547bfe504",
"method": "GET"
},
{
"id": "8dd94fcc-d04c-43ac-9793-ba0351a41a9d",
"method": "GET"
},
{
"id": "201bd700-de90-45b7-83f6-06b8c7322727",
"method": "GET"
}
]
}
}
The processing script:
// Fetch the data from local file in same directory
$str=file_get_contents( __DIR__ . '/blaze-test.json' );
// set the test and result status default - assume pass unless specific fail
$fail=false;
$testname='TestOnBlazemeterWasBroken';
// decode the string data so we can work with it
$json=json_decode( $str );
$results=$json->results ?: false;
if( $results ){
//iterate through the results
foreach( $results as $result ){
$name=$result->name;
$code=$result->responseCode->code;
if( property_exists( $result, 'allTests' ) ){
foreach( $result->allTests as $test ){
// does the test exist in the data and was it failed?
if( property_exists( $test, $testname ) && $test->$testname==true ){
$fail=true;
break 2;
}
}
}
}
$status=$fail ? 'Failed' : 'Passed';
printf(
'
<style>
.Failed{color:red}
.Passed{color:green}
</style>
<h2>Tests run: %d</h2>
<p>The test "%s" within "%s" was <span class="%s">%s</span> with code %s!</p>',
count($results),
$testname,
$name,
$status,
$status,
$code
);
}
The result:
Tests run: 8
The test "TestOnBlazemeterWasBroken" within "See the masters test" was Failed with code 200!
You need to look at your data.
First (if you do not see it in json) you may look at the array.
So just print it (f.e. echo var_export($json_data, true) . PHP_EOL; die;)
or write it into an file.
Looks ok? Then build the loop.
First you loop through the array at the result offset.
And if you do not know what you get on one result then do the same as previously: look at it. Print it.
Same for any deeper loops.
The loop:
// Read JSON file
$json = file_get_contents('Testing.postman_test_run.json');
//Decode JSON
$json_data = json_decode($json, true);
//Traverse array and get the data for students aged less than 20
foreach ($json_data['results'] as $result) {
foreach ($result["allTests"] as $test) {
if (isset($test['TestOnBlazemeterWasBroken'])
and $test['TestOnBlazemeterWasBroken'] === true
) {
// You found it and its true.
echo "TestOnBlazemeterWasBroken is true at {$result['id']}\r\n";
// May collect or print or w/e.
}
}
}
I am currently trying to present a screen shot of a webpage after a user inputs a custom url. I am using google api pagespeedonline to grab the contents of the page as well as fetch the actual data url but when i go to return it on my backend I cant get it to successfuly return just the data url. My current code for doing so is:
public function web_preview(Request $request)
{
try {
$url = $this->check_url($request->input('url'));
} catch (\Exception $e) {
return $this->badRequestResponse($e->getMessage());
}
$info = $this->curl_file_info($url, $this::$ACCEPTABLE_HTML);
if (!$this->is_textual($info))
return $this->clientErrorResponse("Nontextual web asset");
if ($info["http_code"] !== 200)
return $this->clientErrorResponse("URL returned ",$info["http_code"]);
try {
$curl_init = curl_init(
"https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=" + $url + "&key=AIzaSyCxGGWVSSY3fau3cPekSaY765XKRKHerNY&screenshot=true");
curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl_init);
curl_close($curl_init);
//call Google PageSpeed Insights API
//decode json data
$googlepsdata = json_decode($response);
//screenshot data
$snap = $googlepsdata['screenshot-thumbnails']['details']['data'];
} catch(\Exception $e) {
return $this->internalServerError($e->getMessage());
}
// $img = Image::make($snap);
return $snap;
}
and the curl_init should return this:
{
"captchaResult": "CAPTCHA_NOT_NEEDED",
"kind": "pagespeedonline#result",
"id": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"loadingExperience": {
"id": "https://developer.mozilla.org",
"metrics": {
"CUMULATIVE_LAYOUT_SHIFT_SCORE": {
"percentile": 0,
"distributions": [
{
"min": 0,
"max": 10,
"proportion": 0.97998381341452667
},
{
"min": 10,
"max": 25,
"proportion": 0.01036026216807024
},
{
"min": 25,
"proportion": 0.00965592441740298
}
],
"category": "FAST"
},
"LARGEST_CONTENTFUL_PAINT_MS": {
"percentile": 1415,
"distributions": [
{
"min": 0,
"max": 2500,
"proportion": 0.92849265950201776
},
{
"min": 2500,
"max": 4000,
"proportion": 0.046497587955101477
},
{
"min": 4000,
"proportion": 0.025009752542881025
}
],
"category": "FAST"
},
"FIRST_INPUT_DELAY_MS": {
"percentile": 3,
"distributions": [
{
"min": 0,
"max": 100,
"proportion": 0.99082487343845982
},
{
"min": 100,
"max": 300,
"proportion": 0.005724879537811014
},
{
"min": 300,
"proportion": 0.0034502470237293141
}
],
"category": "FAST"
},
"FIRST_CONTENTFUL_PAINT_MS": {
"percentile": 1386,
"distributions": [
{
"min": 0,
"max": 1000,
"proportion": 0.55192771567034826
},
{
"min": 1000,
"max": 3000,
"proportion": 0.4031506848279558
},
{
"min": 3000,
"proportion": 0.044921599501695914
}
],
"category": "AVERAGE"
}
},
"overall_category": "AVERAGE",
"initial_url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"origin_fallback": true
},
"originLoadingExperience": {
"id": "https://developer.mozilla.org",
"metrics": {
"CUMULATIVE_LAYOUT_SHIFT_SCORE": {
"percentile": 0,
"distributions": [
{
"min": 0,
"max": 10,
"proportion": 0.97998381341452667
},
{
"min": 10,
"max": 25,
"proportion": 0.01036026216807024
},
{
"min": 25,
"proportion": 0.00965592441740298
}
],
"category": "FAST"
},
"LARGEST_CONTENTFUL_PAINT_MS": {
"percentile": 1415,
"distributions": [
{
"min": 0,
"max": 2500,
"proportion": 0.92849265950201776
},
{
"min": 2500,
"max": 4000,
"proportion": 0.046497587955101477
},
{
"min": 4000,
"proportion": 0.025009752542881025
}
],
"category": "FAST"
},
"FIRST_INPUT_DELAY_MS": {
"percentile": 3,
"distributions": [
{
"min": 0,
"max": 100,
"proportion": 0.99082487343845982
},
{
"min": 100,
"max": 300,
"proportion": 0.005724879537811014
},
{
"min": 300,
"proportion": 0.0034502470237293141
}
],
"category": "FAST"
},
"FIRST_CONTENTFUL_PAINT_MS": {
"percentile": 1386,
"distributions": [
{
"min": 0,
"max": 1000,
"proportion": 0.55192771567034826
},
{
"min": 1000,
"max": 3000,
"proportion": 0.4031506848279558
},
{
"min": 3000,
"proportion": 0.044921599501695914
}
],
"category": "AVERAGE"
}
},
"overall_category": "AVERAGE",
"initial_url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
},
"lighthouseResult": {
"requestedUrl": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"finalUrl": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"lighthouseVersion": "6.1.0",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/83.0.4103.93 Safari/537.36",
"fetchTime": "2020-08-03T16:07:01.225Z",
"environment": {
"networkUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4143.7 Safari/537.36 Chrome-Lighthouse",
"hostUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/83.0.4103.93 Safari/537.36",
"benchmarkIndex": 674
},
"runWarnings": [],
"configSettings": {
"emulatedFormFactor": "desktop",
"locale": "en-US",
"onlyCategories": [
"performance"
],
"channel": "lr"
},
"audits": {
"critical-request-chains": {
"id": "critical-request-chains",
"title": "Avoid chaining critical requests",
"description": "The Critical Request Chains below show you what resources are loaded with a high priority. Consider reducing the length of chains, reducing the download size of resources, or deferring the download of unnecessary resources to improve page load. [Learn more](https://web.dev/critical-request-chains/).",
"score": null,
"scoreDisplayMode": "informative",
"displayValue": "8 chains found",
"details": {
"type": "criticalrequestchain",
"chains": {
"A5325AC8B1B236F134BF51AA757298E3": {
"children": {
"26.14": {
"request": {
"url": "https://developer.mozilla.org/static/build/styles/l10n-survey.0eeb824ed1eb.css",
"responseReceivedTime": 463937.629765,
"startTime": 463937.613606,
"transferSize": 1436,
"endTime": 463937.629767
}
},
"26.5": {
"request": {
"transferSize": 1570,
"endTime": 463937.662484,
"url": "https://developer.mozilla.org/static/build/styles/auth-modal.be43f0f58a73.css",
"responseReceivedTime": 463937.662481,
"startTime": 463937.611824
}
},
"26.4": {
"request": {
"endTime": 463937.630225,
"startTime": 463937.611595,
"transferSize": 2284,
"responseReceivedTime": 463937.630223,
"url": "https://developer.mozilla.org/static/build/styles/react-header.78d662924939.css"
}
},
"26.12": {
"request": {
"endTime": 463937.634264,
"url": "https://developer.mozilla.org/static/build/styles/banners.e6cd46767c2e.css",
"responseReceivedTime": 463937.63426200004,
"startTime": 463937.613176,
"transferSize": 1376
}
},
"26.8": {
"request": {
"transferSize": 1829,
"startTime": 463937.612959,
"endTime": 463937.662893,
"responseReceivedTime": 463937.662891,
"url": "https://developer.mozilla.org/static/build/styles/prism.a6f275e5032b.css"
}
},
"26.6": {
"request": {
"endTime": 463937.650866,
"url": "https://developer.mozilla.org/static/build/styles/react-mdn.4e0ead71927e.css",
"responseReceivedTime": 463937.65086299996,
"startTime": 463937.612255,
"transferSize": 35533
}
},
"26.13": {
"request": {
"startTime": 463937.613339,
"endTime": 463937.629323,
"transferSize": 1508,
"url": "https://developer.mozilla.org/static/build/styles/mdn-subscriptions.dbb82432d74c.css",
"responseReceivedTime": 463937.62931999995
}
},
"26.7": {
"request": {
"transferSize": 1557,
"startTime": 463937.61266,
"responseReceivedTime": 463937.63605599996,
"endTime": 463937.636059,
"url": "https://developer.mozilla.org/static/build/styles/subscriptions.3cebf84de805.css"
}
}
},
"request": {
"url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"transferSize": 61560,
"responseReceivedTime": 463937.594315,
"endTime": 463937.594317,
"startTime": 463937.53046
}
}
},
"longestChain": {
"transferSize": 1829,
"duration": 132.43300002068281,
"length": 2
}
}
},
"estimated-input-latency": {
"id": "estimated-input-latency",
"title": "Estimated Input Latency",
"description": "Estimated Input Latency is an estimate of how long your app takes to respond to user input, in milliseconds, during the busiest 5s window of page load. If your latency is higher than 50 ms, users may perceive your app as laggy. [Learn more](https://web.dev/estimated-input-latency/).",
"score": 1,
"scoreDisplayMode": "numeric",
"displayValue": "10 ms",
"numericValue": 12.8
},
"total-byte-weight": {
"id": "total-byte-weight",
"title": "Avoids enormous network payloads",
"description": "Large network payloads cost users real money and are highly correlated with long load times. [Learn more](https://web.dev/total-byte-weight/).",
"score": 1,
"scoreDisplayMode": "numeric",
"displayValue": "Total size was 330 KiB",
"details": {
"type": "table",
"headings": [
{
"itemType": "url",
"text": "URL",
"key": "url"
},
{
"text": "Transfer Size",
"itemType": "bytes",
"key": "totalBytes"
}
],
"items": [
{
"url": "https://developer.mozilla.org/static/build/js/react-main.739f5d7ca4fd.js",
"totalBytes": 93235
},
{
"totalBytes": 61560,
"url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
},
{
"url": "https://developer.mozilla.org/static/build/styles/react-mdn.4e0ead71927e.css",
"totalBytes": 35533
},
{
"url": "https://developer.mozilla.org/static/fonts/locales/ZillaSlab-Bold.subset.e96c15f68c68.woff2",
"totalBytes": 34693
},
{
"url": "https://developer.mozilla.org/static/fonts/locales/ZillaSlab-Regular.subset.bbc33fb47cf6.woff2",
"totalBytes": 34437
},
{
"totalBytes": 19085,
"url": "https://www.google-analytics.com/analytics.js"
},
{
"url": "https://developer.mozilla.org/static/build/js/react-bcd-signal.cf0fc711cfa2.js",
"totalBytes": 8283
},
{
"url": "https://cdn.speedcurve.com/js/lux.js?id=108906238",
"totalBytes": 7537
},
{
"url": "https://developer.mozilla.org/static/img/web-docs-sprite.22a6a085cf14.svg",
"totalBytes": 4019
},
{
"url": "https://developer.mozilla.org/static/build/styles/react-header.78d662924939.css",
"totalBytes": 2284
}
]
},
"numericValue": 337833
},
"speed-index": {
"id": "speed-index",
"title": "Speed Index",
"description": "Speed Index shows how quickly the contents of a page are visibly populated. [Learn more](https://web.dev/speed-index/).",
"score": 0.99,
"scoreDisplayMode": "numeric",
"displayValue": "0.8 s",
"numericValue": 775.287095961904
},
"mainthread-work-breakdown": {
"id": "mainthread-work-breakdown",
"title": "Minimizes main-thread work",
"description": "Consider reducing the time spent parsing, compiling and executing JS. You may find delivering smaller JS payloads helps with this. [Learn more](https://web.dev/mainthread-work-breakdown/)",
"score": 1,
"scoreDisplayMode": "numeric",
"displayValue": "0.5 s",
"details": {
"type": "table",
"headings": [
{
"itemType": "text",
"text": "Category",
"key": "groupLabel"
},
{
"itemType": "ms",
"key": "duration",
"text": "Time Spent",
"granularity": 1
}
],
"items": [
{
"duration": 171.94199999999989,
"group": "scriptEvaluation",
"groupLabel": "Script Evaluation"
},
{
"group": "styleLayout",
"groupLabel": "Style & Layout",
"duration": 118.24500000000002
},
{
"group": "other",
"groupLabel": "Other",
"duration": 89.691999999999837
},
{
"groupLabel": "Rendering",
"duration": 32.649999999999984,
"group": "paintCompositeRender"
},
{
"groupLabel": "Parse HTML & CSS",
"duration": 28.025000000000002,
"group": "parseHTML"
},
{
"duration": 16.613,
"group": "scriptParseCompile",
"groupLabel": "Script Parsing & Compilation"
},
{
"group": "garbageCollection",
"groupLabel": "Garbage Collection",
"duration": 2.731
}
]
},
"numericValue": 459.89799999999968
},
"screenshot-thumbnails": {
"id": "screenshot-thumbnails",
"title": "Screenshot Thumbnails",
"description": "This is what the load of your site looked like.",
"score": null,
"scoreDisplayMode": "informative",
"details": {
"type": "filmstrip",
"items": [
{
"timing": 300,
"timestamp": 463937829358,
"data": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRQBAwQEBQQFCQUFCRQNCw0UFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFP/AABEIAFMAeAMB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NAyxQAUAFAHEeO/EGoaRn7JcGH97bL91W4d2DdQeoAreEVLc451Jp2TKHw78UapresXMF7dGeKNHKqUUYxIQOQBngCipCMVoXSnKTsz0asDpCgBqxoo4UDtwKADYoz8o568daAEMSEg7FyDkHHegBwAHQYoAjuLWG7t5IJ4Y5oJFKvFIoZWB6gg8EHJoAkCgEnAyepxQKy3ECKpJAAJ9BQCSWw6gYUAFABQB//9k="
},
with the screenshot/data url being at the very bottom, it appears that the try catch may be hitting the catch but i cant tell why, does anyone have any ideas?
I was given a json file and it need to convert into a php curl but I don't have idea how to do it. can some enlighten me or guide me?
here is the json data given
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "",
"type": "string"
},
{
"key": "username",
"value": "",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
},
{
"key": "Authorization",
"value": "Basic M6NDhhODhjYWUwY2Y0NDE",
"type": "text",
"disabled": true
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "invoice",
"type": "file",
"src": "file.xml"
},
{
"key": "invoice",
"type": "file",
"src": [],
"disabled": true
}
],
"options": {
"raw": {
"language": "xml"
}
}
}
}
and the requirements it to create a PUT request using PHP curl. I hope someone could help :)
I saw a sample here PHP cURL HTTP PUT but I don't know where to put the username and password credentials
You can use header option (-H) for example:
curl -XPUT -H 'Content-Type: application/x-www-form-urlencoded' -H 'Authorization: Basic M6NDhhODhjYWUwY2Y0NDE' -d '>>body content here<<' 'example.com'
so php equivalent will be:
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers)
This question already has answers here:
Cookies on localhost with explicit domain
(24 answers)
Closed 5 years ago.
I have an application that uses saml authentication and passes the response back via a cookie to the return URL the SP provides. The php code looks like this
setcookie('auth', $cred, time() + 30, parse_url($location, PHP_URL_HOST));
error_log($_COOKIE['auth']);
header('Location: ' . $location, true, 303);
die();
The redirect works fine but the cookie is not set. This is confirmed both in php as shown above, and in my application using document.cookies
I've exported the HAR to view the request and it actually looks like the cookie is being set, but it's still not accessible via document.cookie. The way it is supposed to work is that the application changes the window.location to the php file that authenticates, sets the cookie and redirects to the return parameter. Judging by the fact that the request is sent with the cookie, I'd guess that it is being set, but I can't seem to access it.
{
"startedDateTime": "2017-10-27T18:05:36.538Z",
"time": 271.7059999888301,
"request": {
"method": "GET",
"url": "https://supportworkslab.sw.test/sw/selfservice/sso/saml_auth.php?wssinstance=selfservice&returnto=http%3A%2F%2Flocalhost%2Fsw%2Fselfservice",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate, br"
},
{
"name": "Host",
"value": "supportworkslab.sw.test"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.9"
},
{
"name": "Upgrade-Insecure-Requests",
"value": "1"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36"
},
{
"name": "Accept",
"value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
},
{
"name": "Referer",
"value": "http://localhost/sw/selfservice/"
},
{
"name": "Cookie",
"value": "auth=eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM2MGRjLTBhOTI5NWFlLTQxYzEiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D; SimpleSAMLAuthToken=_04a2be772f96fad7c5e2452846c05df5cbd570305e; SimpleSAML=62d6b2ebea7f66b0360a328dcb4f77a7; PHPSESSID=k9hpb09i3omt43bv7gireeuid0"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "Cache-Control",
"value": "no-cache"
}
],
"queryString": [
{
"name": "wssinstance",
"value": "selfservice"
},
{
"name": "returnto",
"value": "http%3A%2F%2Flocalhost%2Fsw%2Fselfservice"
}
],
"cookies": [
{
"name": "auth",
"value": "eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM2MGRjLTBhOTI5NWFlLTQxYzEiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "SimpleSAMLAuthToken",
"value": "_04a2be772f96fad7c5e2452846c05df5cbd570305e",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "SimpleSAML",
"value": "62d6b2ebea7f66b0360a328dcb4f77a7",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "PHPSESSID",
"value": "k9hpb09i3omt43bv7gireeuid0",
"expires": null,
"httpOnly": false,
"secure": false
}
],
"headersSize": 996,
"bodySize": 0
},
"response": {
"status": 303,
"statusText": "See Other",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Date",
"value": "Fri, 27 Oct 2017 18:05:36 GMT"
},
{
"name": "Server",
"value": "Apache"
},
{
"name": "Content-Type",
"value": "text/html"
},
{
"name": "Location",
"value": "http://localhost/sw/selfservice"
},
{
"name": "Set-Cookie",
"value": "SimpleSAML=62d6b2ebea7f66b0360a328dcb4f77a7; path=/; HttpOnly"
},
{
"name": "Set-Cookie",
"value": "PHPSESSID=k9hpb09i3omt43bv7gireeuid0; path=/; HttpOnly"
},
{
"name": "Set-Cookie",
"value": "auth=eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM3NTcwLTBhZTJmNzAzLTNmMTIiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D; expires=Fri, 27-Oct-2017 18:06:36 GMT; Max-Age=60; domain=localhost"
},
{
"name": "Cache-Control",
"value": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
},
{
"name": "Content-Security-Policy",
"value": "default-src 'self' *.sw.test; frame-src *.twitter.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.twitter.com *.twimg.com; style-src 'self' 'unsafe-inline' *.twitter.com *.twimg.com; img-src 'self' data: *.twimg.com *.twitter.com;"
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Keep-Alive",
"value": "timeout=5, max=100"
},
{
"name": "Content-Length",
"value": "0"
},
{
"name": "Expires",
"value": "Thu, 19 Nov 1981 08:52:00 GMT"
}
],
"cookies": [
{
"name": "SimpleSAML",
"value": "62d6b2ebea7f66b0360a328dcb4f77a7",
"path": "/",
"expires": null,
"httpOnly": true,
"secure": false
},
{
"name": "PHPSESSID",
"value": "k9hpb09i3omt43bv7gireeuid0",
"path": "/",
"expires": null,
"httpOnly": true,
"secure": false
},
{
"name": "auth",
"value": "eyJzdWNjZXNzIjoiQXV0aGVudGljYXRpb24gc3VjY2VzcyEiLCJjdXN0aWQiOiJhbGFuYyIsInNlc3Npb25JZCI6IjU5ZjM3NTcwLTBhZTJmNzAzLTNmMTIiLCJ3ZWJGbGFncyI6IjIxNDc0ODk1NTEiLCJjYWxsQ2xhc3MiOiJJbmNpZGVudCIsImFzc2lnbkdyb3VwIjoiU1VQUE9SVCIsImFzc2lnbkFuYWx5c3QiOiIifQ%3D%3D",
"domain": "localhost",
"expires": "2017-10-27T18:06:36.254Z",
"httpOnly": false,
"secure": false
}
],
"content": {
"size": 0,
"mimeType": "text/html",
"compression": 0
},
"redirectURL": "http://localhost/sw/selfservice",
"headersSize": 1104,
"bodySize": 0,
"_transferSize": 1104
},
Make sure your $cred var is defined and a valid string
Make sure the result of the parse_url() function on $location returns a valid string....it has to match exactly the domain you work on so watch out for subdomain issues.
Obviously make sure you check before it expires....60 seconds.
So I have come to a slight issue in phrasing this api response.
I'm trying to phrase the screenshot data from this api response?..
I have tried the below but to no avail!.. It just seems to be NULL?..
any help would be great thanks
$jsonData = json_decode($response, true);
$testt = $jsonData->screenshot->data;
The response:
{
"kind": "pagespeedonline#result",
"id": "http://stackoverflow.com/",
"responseCode": 200,
"title": "Stack Overflow",
"score": 78,
"pageStats": {
"numberResources": 31,
"numberHosts": 11,
"totalRequestBytes": "4412",
"numberStaticResources": 22,
},
"formattedResults": {
"locale": "en_US",
"ruleResults": {
"AvoidLandingPageRedirects": {
"localizedRuleName": "Avoid landing page redirects",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "Your page has no redirects. Learn more about avoiding landing page redirects.",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/AvoidRedirects"
}
]
}
}
]
},
"EnableGzipCompression": {
"localizedRuleName": "Enable compression",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "You have compression enabled. Learn more about enabling compression.",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/EnableCompression"
}
]
}
}
]
},
"LeverageBrowserCaching": {
"localizedRuleName": "Leverage browser caching",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "You have enabled browser caching. Learn more about browser caching recommendations.",
"args": [
{
"type": "HYPERLINK"
}
]
}
}
]
},
"MainResourceServerResponseTime": {
"localizedRuleName": "Reduce server response time",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "Your server responded quickly. Learn more about server response time optimization.",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/Server"
}
]
}
}
]
},
"MinifyCss": {
"localizedRuleName": "Minify CSS",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "Your CSS is minified. Learn more about minifying CSS.",
"args": [
{
"value": "https://developers.google.com/speed/docs/insights/MinifyResources"
}
]
}
}
]
},
"MinifyHTML": {
"ruleImpact": 0.1443,
"urlBlocks": [
{
"header": {
"format": "Compacting HTML code, including any inline JavaScript and CSS contained in it, can save many bytes of data and speed up download and parse times."
}
},
{
"header": {
"format": "Minify HTML for the following resources to reduce their size by $2 ($3 reduction).",
"args": [
{
"value": "https://developers.google.com/speed/docs/insights/MinifyResources"
},
{
"value": "1.4KiB"
},
{
"value": "5%"
}
]
},
"urls": [
{
"result": {
"format": "Minifying $1 could save $2 ($3 reduction) after compression.",
"args": [
{
"type": "URL",
"value": "http://stackoverflow.com/"
},
{
"type": "BYTES",
"value": "1.4KiB"
},
{
"value": "5%"
}
]
}
}
]
}
]
},
"MinifyJavaScript": {
"localizedRuleName": "Minify JavaScript",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "Your JavaScript content is minified. Learn more about minifying JavaScript.",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/MinifyResources"
}
]
}
}
]
},
"MinimizeRenderBlockingResources": {
"localizedRuleName": "Eliminate render-blocking JavaScript and CSS in above-the-fold content",
"urlBlocks": [
{
"header": {
"args": [
{
"type": "INT_LITERAL",
"value": "2"
},
{
"type": "INT_LITERAL",
"value": "3"
}
]
}
},
{
"header": {
"format": "None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML."
}
},
{
"header": {
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/BlockingJS"
}
]
},
"urls": [
{
"result": {
"format": "$1",
"args": [
{
"type": "URL",
"value": "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
}
]
}
},
{
"result": {
"format": "$1",
"args": [
{
"type": "URL",
"value": "http://cdn.sstatic.net/Js/stub.en.js?v=174f553de1d0"
}
]
}
}
]
},
{
"header": {
"format": "Optimize CSS Delivery of the following:",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery"
}
]
},
"urls": [
{
"result": {
"format": "$1",
"args": [
{
"type": "URL",
"value": "http://cdn.sstatic.net/stackoverflow/all.css?v=55bbe6171ff2"
}
]
}
},
{
"result": {
"format": "$1",
"args": [
{
"type": "URL",
"value": "http://cdn-careers.sstatic.net/careers/gethired/company.min.css?v=86ee8c8bfa3e"
}
]
}
},
{
"result": {
"format": "$1",
"args": [
{
"type": "URL",
"value": "http://cdn-careers.sstatic.net/careers/gethired/sidebar.min.css?v=88f3fd5e2263"
}
]
}
}
]
}
]
},
"OptimizeImages": {
"localizedRuleName": "Optimize images",
"ruleImpact": 3.0802000000000005,
"urlBlocks": [
{
"header": {
"format": "Properly formatting and compressing images can save many bytes of data."
}
},
{
"header": {
"format": "Optimize the following images to reduce their size by $2 ($3 reduction).",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/OptimizeImages"
},
{
"type": "BYTES",
"value": "30KiB"
},
{
"type": "PERCENTAGE",
"value": "42%"
}
]
},
"urls": [
{
"result": {
"format": "Losslessly compressing $1 could save $2 ($3 reduction).",
"args": [
{
"type": "URL",
"value": "http://cdn-careers.sstatic.net/careers/gethired/img/careers4-ad-header-so-crop.png?v=f4ca4345dc81"
},
{
"type": "BYTES",
"value": "16.6KiB"
},
{
"type": "PERCENTAGE",
"value": "73%"
}
]
}
},
{
"result": {
"format": "Losslessly compressing $1 could save $2 ($3 reduction).",
"args": [
{
"type": "URL",
"value": "http://cdn.sstatic.net/img/share-sprite-new.png?v=204b1e0e421b"
},
{
"type": "BYTES",
"value": "2.9KiB"
},
{
"type": "PERCENTAGE",
"value": "19%"
}
]
}
},
{
"result": {
"format": "Losslessly compressing $1 could save $2 ($3 reduction).",
"args": [
{
"type": "URL",
"value": "http://cdn.sstatic.net/Img/sprite-herobox.png?v=d173774f3a9f"
},
{
"type": "BYTES",
"value": "2.8KiB"
},
{
"type": "PERCENTAGE",
"value": "43%"
}
]
}
},
{
"result": {
"format": "Losslessly compressing $1 could save $2 ($3 reduction).",
"args": [
{
"type": "URL",
"value": "http://i.stack.imgur.com/Tfe0K.png"
},
{
"type": "BYTES",
"value": "2.6KiB"
},
{
"type": "PERCENTAGE",
"value": "76%"
}
]
}
},
{
"result": {
"format": "Losslessly compressing $1 could save $2 ($3 reduction).",
"args": [
{
"type": "URL",
"value": "http://i.stack.imgur.com/vobok.png"
},
{
"type": "BYTES",
"value": "2.6KiB"
},
{
"type": "PERCENTAGE",
"value": "76%"
}
]
}
},
{
"result": {
"format": "Losslessly compressing $1 could save $2 ($3 reduction).",
"args": [
{
"type": "URL",
"value": "http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b"
},
{
"type": "BYTES",
"value": "1.5KiB"
},
{
"type": "PERCENTAGE",
"value": "9%"
}
]
}
},
{
"result": {
"format": "Losslessly compressing $1 could save $2 ($3 reduction).",
"args": [
{
"type": "URL",
"value": "http://i.stack.imgur.com/G1dzB.png"
},
{
"type": "BYTES",
"value": "962B"
},
{
"type": "PERCENTAGE",
"value": "50%"
}
]
}
}
]
}
]
},
"PrioritizeVisibleContent": {
"localizedRuleName": "Prioritize visible content",
"ruleImpact": 2.0,
"urlBlocks": [
{
"header": {
"format": "Your page requires additional network round trips to render the above-the-fold content. For best performance, reduce the amount of HTML needed to render above-the-fold content."
}
},
{
"header": {
"format": "The entire HTML response was not sufficient to render the above-the-fold content. This usually indicates that additional resources, loaded after HTML parsing, were required to render above-the-fold content. Prioritize visible content that is needed for rendering above-the-fold by including it directly in the HTML response.",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/PrioritizeVisibleContent"
}
]
},
"urls": [
{
"result": {
"format": "Only about $1 of the final above-the-fold content could be rendered with the full HTML response $2.",
"args": [
{
"type": "PERCENTAGE",
"value": "26%"
},
{
"type": "SNAPSHOT_RECT",
"value": "snapshot:5"
}
]
}
}
]
}
]
}
}
},
"version": {
"major": 1,
"minor": 15
},
"screenshot": {
"data": "***************8This is the data i need!!*********",
"height": 240,
"mime_type": "image/jpeg",
"width": 320
}
}
You set the assoc Parameter in json_decode on true, so it will return an array!
You just have to delete true like this:
$jsonData = json_decode($response);
$testt = $jsonData->screenshot->data;
Of course you can change true to false aswell:
$jsonData = json_decode($response, false);
$testt = $jsonData->screenshot->data;
More information about this in the PHP-Manual for json_decode
use it like
$jsonData = json_decode($aa, true);
echo $jsonData['screenshot']['data'];
working code
First, there is an error in your JSON on line 11 that stops json_deocde() returning a valid array (you should remove the trailing comma):
"numberStaticResources": 22,
Second, you are getting an array from json_decode() so you need to use the correct syntax:
$jsonData = json_decode($response, true);
$testt = $jsonData['screenshot']['data'];