می خواهم از api جیتی ماتریکس استفاده کنم صفحه خالی به من نمایش میده اینم کدم هست
require('vendor/autoload.php'); use EntrecoreGTMetrixClientGTMetrixClient; use EntrecoreGTMetrixClientGTMetrixTest; $client = new GTMetrixClient(); $client->setUsername('vdv@mail.com'); $client->setAPIKey('641e5bb0b82b8b79'); $client->getLocations(); $client->getBrowsers(); $test = $client->startTest('http://www.codd.ir/fa'); //Wait for result while ($test->getState() != GTMetrixTest::STATE_COMPLETED && $test->getState() != GTMetrixTest::STATE_ERROR) { $client->getTestStatus($test); sleep(5); }
حل شد
`require_once('vendor/autoload.php'); use EntrecoreGTMetrixClientGTMetrixClient; use EntrecoreGTMetrixClientGTMetrixTest; $client = new GTMetrixClient(); $client->setUsername('netwons@mail.com'); $client->setAPIKey('۶۴۱e۵bb۰b۸۲b۸۳۶۰b۲۱۲۵fe۱۱۲۳۳۵b۷۹'); $client->getLocations(); $client->getBrowsers(); $test = $client->startTest('https://www.coms.ir/fa'); //Wait for result while ($test->getState() != GTMetrixTest::STATE_COMPLETED && $test->getState() != GTMetrixTest::STATE_ERROR) { $final = $client->getTestStatus($test); } echo '<pre>'; $file=fopen('t.txt', 'w'); fwrite($file, string);
من می خواهم در یک فایل دخیره کنم اما finalرو خالی نمایش میده
@masoudproton
اگر از لاراول استفاده میکنید از $final یک dd بگیرید ببینید چی برمیگردونه. اگر هم لاراول نیست از var_dump استفاده کنید
درود..
از وابستگی جی متریکس استفاده کنید:
https://packagist.org/packages/philcook/gtmetrix
از همون استفاده میکنم اما سرعتش خیلی کمه و بعضی وقت ها ارور میده ``` require_once('vendor/autoload.php'); use Entrecore\GTMetrixClient\GTMetrixClient; use Entrecore\GTMetrixClient\GTMetrixTest; $client = new GTMetrixClient(); $client->setUsername('masoudproton@protonmail.com'); $client->setAPIKey('db۷۹۴۸۲c۹eae۹f۹f۹e۱d۹abb۲۲۲۳۱۸b۶'); // $client->setUsername(' netwons@gmail.com'); // $client->setAPIKey('۲efb۵b۶ac۰۹۲a۸۹bac۰۲۱۸۷۲۹af۶۰d۵c'); $client->getLocations(); $client->getBrowsers(); $test = $client->startTest('https://www.roocket.ir'); while ($test->getState() != GTMetrixTest::STATE_COMPLETED && $test->getState() != GTMetrixTest::STATE_ERROR) { $final = $client->getTestStatus($test); } echo "<pre>"; print_r($final); echo "</pre>"; file_put_contents('yourfile.txt',print_r($final,TRUE)); $r=file_get_contents('yourfile.txt'); preg_match_all("/https:\/\/gtmetrix.com\/reports\/www.coms.ir\/[\W\w]*? /im", $r,$m); $file۱۰=fopen('yourfile۱.txt', 'w'); foreach ($m[۰] as $ee) { fwrite($file۱۰, $ee); } ارورش اینه Fatal error: Uncaught Entrecore\GTMetrixClient\GTMetrixException: API error ۴۰۲: {"error":"Maximum number of API calls reached. Your next API credit refill will be on Mon, ۱۴ Jan ۲۰۱۹ ۰۸:۳۰ (PST)"} in /opt/lampp/htdocs/vendor/philcook/gtmetrix/src/GTMetrixClient.php:۱۰۶ Stack trace: #۰ /opt/lampp/htdocs/vendor/philcook/gtmetrix/src/GTMetrixClient.php(۲۰۶): Entrecore\GTMetrixClient\GTMetrixClient->apiCall('/test', Array) #۱ /opt/lampp/htdocs/gt.php(۱۳): Entrecore\GTMetrixClient\GTMetrixClient->startTest('https://www.com...') #۲ {main} thrown in /opt/lampp/htdocs/vendor/philcook/gtmetrix/src/GTMetrixClient.php on line ۱۰۶
@masoudproton
خطا نشون میده مدت زمان استفاده API رایگان به پایان رسیده...
برای استفاده از API دائمی باید حسابتان ارتقا بدید...
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟