3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace app\controller; use app\item\BookManager; use app\item\AccountManager; use app\item\TagManager; use app\model\Url; use app\view\ItemView; class BookController { /** * URL入力で検索 * DBになければAPIから取得して返す * book/embed で実行 * * searchAction() と違い supplierName, itemKind の信頼性がないので * (悪意あるユーザーが妙な情報をPOSTしうるので) * new Url($inputUrl) でURL解析し supplierName, itemKind を得る */ public function embedAction(): void { // 検索条件 $requestData = json_decode(file_get_contents('php://input'), true); $inputUrl = isset($requestData['url']) ? $requestData['url'] : null; $isLatestRequest = isset($requestData['is_latest_request']) ? $requestData['is_latest_request'] : null; // URL解析し, 一意のデータを検索 $urlInst = new Url($inputUrl); $className = 'app\\item\\' . ucfirst($urlInst->supplierName) . ucfirst($urlInst->itemKind); // ex 'app\\item\\AmazonBook' $supplierItemInst = new $className(); $stmt = $supplierItemInst->findByUrl($urlInst); $bookInst = $stmt->fetch(); // なければ || 最新の要請があれば if (!$bookInst || $isLatestRequest ) { // サプライヤークラス $className = 'app\\supplier\\' . ucfirst($urlInst->supplierName) . 'ApiManager'; // ex 'app\\supplier\\AmazonApiManager' $supplierApiManagerInst = new $className(); // APIのレスポンス取得, 構造の変換, レスポンス保存 $response = $supplierApiManagerInst->fetchByUrl($urlInst); $supplierResponseId = $supplierApiManagerInst->saveSupplierResponse('embed', $response); $bookInstAry = $supplierApiManagerInst->responseToSupplierItemInstAry($response); // レスポンス変換失敗は false が返る /* ★ここに100~120行目と同じコードを書くことがイヤです... */ } $view = new ItemView(); $view->renderInst($bookInst); } /** * ワード入力で検索 * DBになければAPIから取得して返す * book/search で実行 * * フロントからワード入力で検索実行すると * まず checkSearchedWithin24() が実行され * is_searched_within24 がフロントに返るのでそれをPOSTに含めて * 当メソッドが実行される * is_searched_within24 = true ならDBから取得してくる * is_searched_within24 = false ならAPIから検索してくる */ public function searchAction(): void { // 検索条件 $requestData = json_decode(file_get_contents('php://input'), true); $searchWords = isset($requestData['search_words']) ? $requestData['search_words'] : null; $supplierName = isset($requestData['supplier_name']) ? $requestData['supplier_name'] : null; $itemKind = isset($requestData['item_kind']) ? $requestData['item_kind'] : null; $offset = isset($requestData['offset']) ? $requestData['offset'] : null; $isSearchedWithin24 = isset($requestData['is_searched_within24']) ? $requestData['is_searched_within24'] : null; // 24時間以内に検索しているか否かで分岐 if ($isSearchedWithin24) { // 検索条件にあった本群を取得 $conditions = ['search_words'=>$searchWords, 'supplier_name'=>$supplierName, 'item_kind'=>$itemKind, 'offset'=>$offset]; $bookManagerInst = new BookManager(); $resultBookInstAry = $bookManagerInst->findByWords($conditions); } else { // サプライヤークラス $apiConditions = ['search_words'=>$searchWords, 'item_kind'=>$itemKind, 'offset'=>$offset]; $className = 'app\\supplier\\' . ucfirst($supplierName) . 'ApiManager'; // ex 'app\\supplier\\AmazonApiManager' $supplierApiManagerInst = new $className(); // APIのレスポンス取得, 構造の変換, レスポンス保存 $response = $supplierApiManagerInst->fetchByWords($apiConditions); $supplierResponseId = $supplierApiManagerInst->saveSupplierResponse('search', $response); $bookInstAry = $supplierApiManagerInst->responseToSupplierItemInstAry($response); // レスポンス変換失敗は false が返る // DBに保存 $resultBookInstAry = []; if ($bookInstAry) { foreach($bookInstAry as $bookInst) { // book $bookInst->setSupplierResponseId($supplierResponseId); $bookManagerInst = new BookManager(); $bookManagerInst->findOrInsert($bookInst); // accounts $accountManagerInst = new AccountManager(); foreach($bookInst->getAccountInstAry() as $accountInst) { $accountInst->setSupplierResponseId($supplierResponseId); $accountManagerInst->findOrInsert($accountInst); $accountInst->addAccountInstAry($accountInst); } $bookManagerInst->relateBookAccounts($bookInst->getId(), $bookInst->getAccountInstAry()); // tags $tagManagerInst = new TagManager(); foreach($bookInst->getTagInstAry() as $tagInst) { $tagManagerInst->findOrInsert($tagInst); $bookInst->addTagInstAry($tagInst); } $bookManagerInst->relateBookTags($bookInst->getId(), $bookInst->getTagInstAry()); // 返り値にセット $resultBookInstAry[] = $bookInst; } } } $view = new ItemView(); $view->renderInstAry($resultBookInstAry); } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.00.0130.00819.82
8.4.150.0020.00014.05
8.4.140.0090.01317.18
8.4.130.0120.00817.96
8.4.120.0120.00924.34
8.4.110.0120.00318.59
8.4.100.0120.00417.75
8.4.90.0100.00617.54
8.4.80.0040.00517.88
8.4.70.0040.00417.89
8.4.60.0040.00617.84
8.4.50.0090.01420.22
8.4.40.0120.00917.62
8.4.30.0090.00920.63
8.4.20.0100.01017.80
8.4.10.0100.01021.84
8.3.280.0020.00014.05
8.3.270.0110.00816.86
8.3.260.0120.00816.55
8.3.250.0110.00819.08
8.3.240.0130.00516.61
8.3.230.0100.00916.71
8.3.220.0060.01316.60
8.3.210.0080.01116.44
8.3.200.0110.01018.89
8.3.190.0110.00417.08
8.3.180.0100.00816.46
8.3.170.0060.01218.79
8.3.160.0070.01116.76
8.3.150.0070.01118.91
8.3.140.0130.00718.23
8.3.130.0030.01318.18
8.3.120.0100.00018.91
8.3.110.0040.00416.75
8.3.100.0070.00316.62
8.3.90.0080.00026.77
8.3.80.0070.00317.97
8.3.70.0180.00416.63
8.3.60.0150.00318.30
8.3.50.0040.01818.35
8.3.40.0060.01021.96
8.3.30.0070.00719.13
8.3.20.0060.00324.18
8.3.10.0040.00424.66
8.3.00.0030.00526.16
8.2.290.0090.00919.05
8.2.280.0120.00816.59
8.2.270.0120.00616.92
8.2.260.0110.00718.94
8.2.250.0030.00616.66
8.2.240.0040.00417.09
8.2.230.0000.00820.94
8.2.220.0030.00637.54
8.2.210.0000.00826.77
8.2.200.0060.00316.38
8.2.190.0090.00616.63
8.2.180.0000.01416.63
8.2.170.0090.00918.96
8.2.160.0070.00722.96
8.2.150.0050.00325.66
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0050.00322.20
8.2.110.0100.00022.13
8.2.100.0060.00617.69
8.2.90.0340.00917.38
8.2.80.0300.00717.13
8.2.70.0260.00917.38
8.2.60.0270.00817.13
8.2.50.0270.00317.13
8.2.40.0310.00417.13
8.2.30.0250.00617.25
8.2.20.0260.00617.13
8.2.10.0270.00517.13
8.2.00.0270.00217.38
8.1.330.0140.00516.49
8.1.320.0120.00617.70
8.1.310.0110.00317.94
8.1.300.0150.00418.22
8.1.290.0090.00030.84
8.1.280.0120.00925.92
8.1.270.0040.00424.66
8.1.260.0080.00026.35
8.1.250.0050.00228.09
8.1.240.0000.01022.53
8.1.230.0080.00320.94
8.1.220.0300.00016.85
8.1.210.0240.00717.13
8.1.200.0230.00616.88
8.1.190.0270.00318.52
8.1.180.0260.00517.25
8.1.170.0310.00017.00
8.1.160.0310.00317.00
8.1.150.0210.01017.25
8.1.140.0220.00819.00
8.1.130.0190.00916.88
8.1.120.0200.00816.88
8.1.110.0270.00017.10
8.1.100.0220.00817.00
8.1.90.0250.00617.13
8.1.80.0240.00716.88
8.1.70.0280.00017.00
8.1.60.0230.00717.13
8.1.50.0240.00616.87
8.1.40.0220.00916.96
8.1.30.0190.01117.13
8.1.20.0250.00517.00
8.1.10.0270.00617.13
8.1.00.0300.00017.13
8.0.300.0390.00016.80
8.0.290.0190.01016.80
8.0.280.0180.01416.80
8.0.270.0240.00616.80
8.0.260.0270.00016.80
8.0.250.0180.01116.80
8.0.240.0200.01016.80
8.0.230.0270.00316.80
8.0.220.0260.00316.80
8.0.210.0260.00316.80
8.0.200.0280.00016.80
8.0.190.0250.00316.80
8.0.180.0230.01016.80
8.0.170.0310.00216.80
8.0.160.0330.00016.80
8.0.150.0230.00516.80
8.0.140.0330.00016.80
8.0.130.0210.00616.80
8.0.120.0240.00416.80
8.0.110.0250.00316.80
8.0.100.0190.00816.80
8.0.90.0290.00016.80
8.0.80.0250.00316.80
8.0.70.0220.00716.80
8.0.60.0280.00016.80
8.0.50.0190.01016.80
8.0.30.0250.00316.80
8.0.20.0210.00816.80
8.0.10.0240.00716.80

preferences:
128.57 ms | 403 KiB | 5 Q