note 111160 added to function.sqlsrv-num-rows

From: Date: Mon, 21 Jan 2013 14:04:40 +0000
Subject: note 111160 added to function.sqlsrv-num-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-193298@lists.php.net to get a copy of this message
Try to avoid using this function if you need good performance. Specifying "Scrollable" in the options will make you queries take ages to run. If your result contains less than 5000 rows (might vary on different hardware) its faster to not use "Scrollable" and loop over them in php instead. If you need to check if a result contains rows use "sqlsrv_has_rows()", this function works without "Scrollable". After removing all my "Scrollable" queries, my page loadtime went from 900ms to 60ms. To demonstrate, here is a query that returns 100 rows: <?php for($i = 0; $i < 100; $i++) { $q = "SELECT sku,name FROM product WHERE visible = 1"; $result = sqlsrv_query($db,$q,array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); while($row = sqlsrv_fetch_array($result)) {} } ?> This takes about 10s! Thats 10 qps.. Now if we remove "Scrollable": <?php for($i = 0; $i < 100; $i++) { $q = "SELECT sku,name FROM product WHERE visible = 1"; $result = sqlsrv_query($db,$q); while($row = sqlsrv_fetch_array($result)) {} } ?> This will run in 300ms, about 334 qps! ---- Server IP: 69.147.83.199 Probable Submitter: 62.95.13.20 ---- Manual Page -- http://php.net/manual/en/function.sqlsrv-num-rows.php Edit -- https://master.php.net/note/edit/111160 Del: integrated -- https://master.php.net/note/delete/111160/integrated Del: useless -- https://master.php.net/note/delete/111160/useless Del: bad code -- https://master.php.net/note/delete/111160/bad+code Del: spam -- https://master.php.net/note/delete/111160/spam Del: non-english -- https://master.php.net/note/delete/111160/non-english Del: in docs -- https://master.php.net/note/delete/111160/in+docs Del: other reasons-- https://master.php.net/note/delete/111160 Reject -- https://master.php.net/note/reject/111160 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193298) next »