Posted in php function
3744
2:46 am, April 13, 2023
 

function causing slow load time

i had this function matching a uid using a binary select query. The sites were loading in about 8 full seconds according to my load timer, sometimes up to 12 seconds!

So this was running on old site code, really just a big mess. 

But i copied it to another site and tested each function and the sql that ran on them to see which one was causing the lag time. 

This query took about 0.03 seconds to return when tested. 

SELECT $field_name FROM $table_name where binary $uid_field_name = '$uid' LIMIT 1

I think I added the binary option as it was not selecting the uid correctly, but removing the binary seems to not make any difference to the results, but reduces this query time a lot. 

Test site with 8+k pages was loading in:

Page generated in 8.3164 seconds.

Then after removing the binary select query and just using a normal query, the same page is now. 

Page generated in 0.2958 seconds.

So makes a large difference, and more depending on the page or record number i think. 

PHP

function get_single_by_uid($field_name,$table_name,$uid,$uid_field_name = "uid") {
	global $db;
	$x = "";
	$uid = mysqli_real_escape_string($db, $uid);
	$field_name = mysqli_real_escape_string($db, $field_name);
	$table_name = mysqli_real_escape_string($db, $table_name);
	//$sql = "SELECT $field_name FROM $table_name where binary $uid_field_name = '$uid' LIMIT 1";
	$sql = "SELECT $field_name FROM $table_name where $uid_field_name = '$uid' LIMIT 1";
	$result = $db->query($sql);
	if(!$result) { return false; }
	$x = mysqli_fetch_assoc($result);	
	if(isset($x[$field_name])) {
		return(politeify($x[$field_name]));
	} 
	return false;
}

View Statistics
This Week
71
This Month
182
This Year
976

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Items in php function
Related Search Terms
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown
Random CSS Property

hue-rotate()

The hue-rotate() CSS function rotates the hue of an element and its contents. Its result is a <filter-function>.
hue-rotate() css reference