public function fetchIterator() { $obj = $this; return Stats::trace($this->_humanizedSql, $this->_boundValues, function () use($obj) { $pdoStatement = $obj->_createPdoStatement(); return new StatementIterator($pdoStatement); }); }
public static function getNumberOfQueries() { $sum = 0; $queries = self::queries(); array_walk($queries, function ($data, $request) use(&$sum) { $sum += Stats::getRequestNumberOfQueries($request); }); return $sum; }
public function poll() { Stats::reset(); session_write_close(); $stop = Clock::now()->plusSeconds(self::TIMEOUT); while (true) { if (!$stop->isAfter(Clock::now()) || connection_aborted()) { $this->layout->renderAjax("[]"); return; } session_start(); $events = Event::loadNew(); session_write_close(); if ($events) { $this->layout->renderAjax(Json::encode(Arrays::map($events, function (Event $event) { return $event->toJsonArray(); }))); return; } Stats::reset(); usleep(100 * 1000); } }
/** * @test */ public function shouldFetchIteratorAndFetchRelationsInBatches() { //given Product::create(array('name' => '1', 'id_category' => Category::create(array('name' => 'cat1'))->getId())); Product::create(array('name' => '2', 'id_category' => Category::create(array('name' => 'cat2'))->getId())); Product::create(array('name' => '3', 'id_category' => Category::create(array('name' => 'cat3'))->getId())); Stats::reset(); //when $results = Product::where()->with('category')->fetchIterator(2); //then Assert::thatArray(iterator_to_array($results))->extracting('name')->containsExactly('1', '2', '3'); $this->assertEquals(3, Stats::getNumberOfQueries()); }
/** * @test */ public function shouldTraceRequestInfo() { //given Config::overrideProperty('debug')->with(true); Route::resource('restful'); $this->get('/restful?param=1'); //when $queries = Arrays::first(Stats::queries()); //then ArrayAssert::that($queries['request_params'][0])->hasSize(1)->containsKeyAndValue(array('param' => 1)); }
private function _createHttpTraceRequest($request, $params = array()) { $_SERVER['REQUEST_URI'] = $request; Stats::traceHttpRequest($params); }
private function _logRequestIfDebugEnabled() { if (Config::getValue('debug')) { Stats::traceHttpRequest($this->currentControllerObject->params); } }