jainischalverma Posted March 2, 2010 Share Posted March 2, 2010 Hi, This is my issue :- I am using a function that can generate color variations from a user-provided color HEX code. For example, someone input #FF0000 as the input, the function can take the color code and another variable for intensity and produce shade of that same color. This is the function :- function hexDarker($hex,$factor = 30) { $new_hex = ''; $base['R'] = hexdec($hex{0}.$hex{1}); $base['G'] = hexdec($hex{2}.$hex{3}); $base['B'] = hexdec($hex{4}.$hex{5}); foreach ($base as $k => $v) { $amount = $v / 100; $amount = round($amount * $factor); $new_decimal = $v - $amount; $new_hex_component = dechex($new_decimal); if(strlen($new_hex_component) < 2) { $new_hex_component = "0".$new_hex_component; } $new_hex .= $new_hex_component; } return $new_hex; } The function works flawlessly but my problem is this :- I am generating four kinds of values using the same function and storing the values in four variables like this (where $sp_color is the hex value provided) :- <?php $bgCol = hexDarker($sp_color, 80); $logocol = hexDarker($sp_color, 60); $linksCol = hexDarker($sp_color, 40); $linksCollight = hexDarker($sp_color, 10); ?> Now when I use these values in a website design, they work, but everytime the page changes, the implementation of the colors is a bit delayed. Actually, the calls generate the values every time the pages are changed/refreshed which is causing a slight delay. Because of this, the default or no colors are shown on elements before they get filled with the above generated colors. I need a way of either storing these values and applying some kind of loop to check the change in the variable ($sp_color). I am lost. Please help. caching ?? Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/ Share on other sites More sharing options...
Dennis1986 Posted March 2, 2010 Share Posted March 2, 2010 ...Because of this, the default or no colors are shown on elements before they get filled with the above generated colors... That shouldn't be possible in PHP :S Are you sure the issue is PHP related? PHP doesn't print out some content first and some other content later that should be printed out earlier. I mean, you shouldn't be able to see the delay like that :S Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020689 Share on other sites More sharing options...
jainischalverma Posted March 3, 2010 Author Share Posted March 3, 2010 Want to experience the issue ? go to http://colorpress.blogohblog.net and try changing the pages.. home to other page and back . You will see elements defaulting to original colors instead of taking the new ones. Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020691 Share on other sites More sharing options...
jainischalverma Posted March 3, 2010 Author Share Posted March 3, 2010 Ha HA ... another thing I just saw.. This thing's only happening in FIREFOX. IE is smooth.... Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020698 Share on other sites More sharing options...
Dennis1986 Posted March 3, 2010 Share Posted March 3, 2010 Arh okay like that. It's because you're calling for a PHP file for your stylesheet element which can be delayed (and stopped) like on this screenshot: http://img138.imageshack.us/img138/2113/cssdelay.jpg To fix this you have to include the css of that PHP file into the main file/page/css... ...or setup a cache for the file in order to speed up the loading of it. <?php header('Content-type: text/css'); header("Cache-Control: must-revalidate"); $offset = 72000 ; $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; header($ExpStr); ?> Although this kind of caching is time based and won't revalidate on change of data/output. The third option is to create the CSS file with PHP and then revalidate with a function/class on every page load and re-create the CSS file if data has changed. edit: The reason IE is "smooth" is because it DOES cache the php file (IE tends to cache everything even when it shouldn't :-/ ) Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020700 Share on other sites More sharing options...
jainischalverma Posted March 3, 2010 Author Share Posted March 3, 2010 this is a wordpress theme and if you know..... i have made some theme options which can take user input. So, there is a style.php file which renders CSS through php (I hope you get my point). In this style.php file , I have made those 4 calls to the hex function. So, help me how to revalidate with a funcion on every page load -> this is where i am stuck! The third option is to create the CSS file with PHP and then revalidate with a function/class on every page load and re-create the CSS file if data has changed. edit: The reason IE is "smooth" is because it DOES cache the php file (IE tends to cache everything even when it shouldn't :-/ ) Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020705 Share on other sites More sharing options...
jainischalverma Posted March 3, 2010 Author Share Posted March 3, 2010 By the way, I just tried your cache solution for this css file.. guess what.. It works flawlessly... AMAZING. Mr. Dennis, you are a HERO What prize will you like ? Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020709 Share on other sites More sharing options...
Dennis1986 Posted March 3, 2010 Share Posted March 3, 2010 Prize? I thought this community was free of charge. But since you ask... a woman! Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020719 Share on other sites More sharing options...
jainischalverma Posted March 3, 2010 Author Share Posted March 3, 2010 women are everywhere mate... just look around Link to comment https://forums.phpfreaks.com/topic/193948-need-urgent-help-with-variables-and-function/#findComment-1020722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.