@@ -189,7 +189,8 @@ function gradeTTFBForStep($ttfb, $latency, $localPaths, &$target) {
189189 if ( !isset ($ score ) )
190190 {
191191 $ target = getTargetTTFBForStep ($ localPaths , $ latency );
192- $ score = (int )min (max (100 - (($ ttfb - $ target ) / 10 ), 0 ), 100 );
192+ $ stepTime = $ latency <= 100 ? 10 : 15 ;
193+ $ score = (int )min (max (100 - (($ ttfb - $ target ) / $ stepTime ), 0 ), 100 );
193194 }
194195 }
195196
@@ -202,8 +203,9 @@ function gradeTTFBForStep($ttfb, $latency, $localPaths, &$target) {
202203 * @param int $rtt The latency if set, or null
203204 * @return int|null The target TTFB or null if it can't get determined
204205 */
205- function getTargetTTFBForStep ($ localPaths , $ rtt ) {
206+ function getTargetTTFBForStep ($ localPaths , & $ rtt ) {
206207 $ target = NULL ;
208+ $ latency = $ rtt ;
207209
208210 // load the object data (unavoidable, we need the socket connect time to the first host)
209211 require_once ('object_detail.inc ' );
@@ -223,14 +225,15 @@ function getTargetTTFBForStep($localPaths, $rtt) {
223225 if ($ rtt > 0 && (!isset ($ connect_ms ) || $ connect_ms > 3000 || $ connect_ms < 0 ))
224226 $ rtt += 100 ; // allow for an additional 100ms to reach the server on top of the traffic-shaped RTT
225227 else
226- $ rtt = $ connect_ms ;
228+ $ rtt = max ( $ connect_ms, $ latency ) ;
227229 }
228230
229231 // allow for a minimum of 100ms for the RTT
230232 $ rtt = max ($ rtt , 100 );
231233
232234 $ ssl_ms = 0 ;
233235 $ i = 0 ;
236+ $ request_start = null ;
234237 while (isset ($ requests [$ i ])) {
235238 if (isset ($ requests [$ i ]['contentType ' ]) &&
236239 (stripos ($ requests [$ i ]['contentType ' ], 'ocsp ' ) !== false ||
@@ -239,12 +242,20 @@ function getTargetTTFBForStep($localPaths, $rtt) {
239242 } else {
240243 if ($ requests [$ i ]['is_secure ' ])
241244 $ ssl_ms = $ rtt ;
245+ if (isset ($ requests [$ i ]['ttfb_start ' ]) && $ requests [$ i ]['ttfb_start ' ] > 0 )
246+ $ request_start = $ requests [$ i ]['ttfb_start ' ];
242247 break ;
243248 }
244249 }
245250
246- // RTT's: DNS + Socket Connect + HTTP Request + 100ms allowance
247- $ target = ($ rtt * 3 ) + $ ssl_ms + 100 ;
251+ // Set the target based off of the time when the first request was sent (if available)
252+ $ buffer = $ latency > 100 ? 150 : 100 ;
253+ if (isset ($ request_start )) {
254+ $ target = $ request_start + $ rtt + $ buffer ;
255+ } else {
256+ // RTT's: DNS + Socket Connect + HTTP Request + 100ms allowance
257+ $ target = ($ rtt * 3 ) + $ ssl_ms + $ buffer ;
258+ }
248259 }
249260
250261 return $ target ;
0 commit comments