Friday, October 2, 2009
Warning: number_format() expects parameter 1 to be double
I ran into this error when I was working on the Google Custom Search API. I've never run into it before. I'm passing the estimated number of search results through to a number_format() which is currently passing through the number 10. Unfortunately it's throwing this error. I haven't figured it out yet, if anyone knows please post the solution so others can find it as well.
Tuesday, August 4, 2009
OpenX Javascript or CSS not loading
The get.max_value_length value of your web server settings does not allow to use long URL paths. This might lead to JavaScript and CSS files not properly being included. To fix this you have 2 options:
- Modify your config setting for OpenX to disable combining/compressing CSS/JS files (this only effects the admin panel).
[ui]combineAssets=0
- Modify php.ini to extend the length of your GET variable values. The default setting for PHP 5.3 is 512.
How to find the locaion of php.ini
To find the location of your php.ini file, copy and paste the below code into a php file and upload it to your server.
When you access the file it will look like the below image. The red arrow is pointing to the location of your php.ini file. In Linux environments this is the most common location.
<?php phpinfo(); ?>
When you access the file it will look like the below image. The red arrow is pointing to the location of your php.ini file. In Linux environments this is the most common location.
A quick guide to Smarty caching
When you first jump into Smarty Template Engine caching it can be a bit confusing and overwhelming till you get your feet wet and begin to understand some core concepts of how Smarty works. Now that I'm beginning to understand it, I see how we can't live without it!
Basic Caching
Smarty has a _compiled folder which is used to cache the parsed versions of templates (ie - Smarty's "template code" is replaced with actual PHP and stored in the _compiled folder). Smarty also has a _cache folder which will actually store individual templates.
For smaller web sites, Smarty's basic caching is very effective and simple. You simply enable caching and define a lifetime
Group Caching
Smarty offers the ability to group your templates. So if you need to lets say, clear the templates for the news section of your web site, you can simply execute $smarty->clear_cache(null,'news'); and all of your news template's caches will be cleared. This same technique can be utilized for caching dynamic pages with a ?id= within the URL. You can apply multiple group tags to identify a group, or an individual element. In the below example, index.tpl will be used to view all articles, but to decrease database load you want to cache each article's contents. By defining news|$article_id you are creating a sub group of news for each article id, meaning they won't be overwritten by other articles.
By utilizing the is_cached() function we see the core benefit of Smarty. If the cache exists, we don't need to run queries to or any parsing on the article itself, so we can skip all of this. This is very beneficial to reduce SQL server load. It's much less server processing to see if a file exists than it is to run queries/parsing on an article.
That's the basics of Smarty caching.
Basic Caching
Smarty has a _compiled folder which is used to cache the parsed versions of templates (ie - Smarty's "template code" is replaced with actual PHP and stored in the _compiled folder). Smarty also has a _cache folder which will actually store individual templates.
For smaller web sites, Smarty's basic caching is very effective and simple. You simply enable caching and define a lifetime
caching = 2; // lifetime is per cache
// set the cache_lifetime for index.tpl to 5 minutes
$smarty->cache_lifetime = 300;
$smarty->display('index.tpl');
// set the cache_lifetime for home.tpl to 1 hour
$smarty->cache_lifetime = 3600;
$smarty->display('home.tpl');
// NOTE: the following $cache_lifetime setting will not work when $caching = 2.
// The cache lifetime for home.tpl has already been set
// to 1 hour, and will no longer respect the value of $cache_lifetime.
// The home.tpl cache will still expire after 1 hour.
$smarty->cache_lifetime = 30; // 30 seconds
$smarty->display('home.tpl');
?>Group Caching
Smarty offers the ability to group your templates. So if you need to lets say, clear the templates for the news section of your web site, you can simply execute $smarty->clear_cache(null,'news'); and all of your news template's caches will be cleared. This same technique can be utilized for caching dynamic pages with a ?id= within the URL. You can apply multiple group tags to identify a group, or an individual element. In the below example, index.tpl will be used to view all articles, but to decrease database load you want to cache each article's contents. By defining news|$article_id you are creating a sub group of news for each article id, meaning they won't be overwritten by other articles.
caching = 1;
$my_cache_id = $_GET['article_id'];
if(!$smarty->is_cached('index.tpl', 'news|'.$my_cache_id)) {
// No cache available, do variable assignments here.
$contents = get_database_contents();
$smarty->assign($contents);
}
$smarty->display('index.tpl', 'news|'.$my_cache_id);
?>By utilizing the is_cached() function we see the core benefit of Smarty. If the cache exists, we don't need to run queries to or any parsing on the article itself, so we can skip all of this. This is very beneficial to reduce SQL server load. It's much less server processing to see if a file exists than it is to run queries/parsing on an article.
That's the basics of Smarty caching.
Thursday, July 30, 2009
Smarty syntax error: unrecognized tag 'dynamic' and Block functions
I ran into this error while working with Smarty caching. This error is caused by a "dynamic" block function not being registered with Smarty. A block function is a function which essentially will take a section of content and execute a function on that content. Because of this, Smarty will not cache it. Notice in this example the smarty_block_dynamic function simply returns the content. Because it was defined as "dynamic" you can use the Smarty dynamic tags to wrap content and avoid the caching engine.
This is not a default tag in Smarty and will fail if you have not registered the block function as provided in the example.
This is not a default tag in Smarty and will fail if you have not registered the block function as provided in the example.
Tuesday, July 21, 2009
Feedburner Custom URL
Feedburner offers a custom URL service which will allow for you to link to any domain/subdomain combination instead of feeds*.feedburner.com. The good news is anyone can do it. You can find the Branding settings by logging info feedburner and clicking "My Account" and then "My Brand".
Google will then offer instructions on how to do this. On a shared hosting service you can submit a support request to have the DNS entries made for you, on a dedicated/self hosted you can do it yourself. These changes have to resolve just as any other DNS, so the effects are not immediate.
Note: I just changed web hosts and it appears that the DNS entry url that Google provided changed as well. That leads me to believe that if your primary domain changes nameservers that Google would issue a new entry value.
Google will then offer instructions on how to do this. On a shared hosting service you can submit a support request to have the DNS entries made for you, on a dedicated/self hosted you can do it yourself. These changes have to resolve just as any other DNS, so the effects are not immediate.
Note: I just changed web hosts and it appears that the DNS entry url that Google provided changed as well. That leads me to believe that if your primary domain changes nameservers that Google would issue a new entry value.
Monday, July 20, 2009
How to execute PHP files via cron in CPanel
There are two ways that I know of (I'm sure there's more) to execute php files within cron commands.
This first method will utilize relative paths. Meaning if within this file you utilize a require_once(../file.php); it will load the file accordingly. Whereas if you use the second route
you must utilize absolute paths within your file. Including a file using a relative path (like ../) will throw an error, you must define the full path of the file. Save yourself a headache when you go to transfer hosts, utilize the first method.
php -q /home/USER/public_html/cron/path-to-file.php
This first method will utilize relative paths. Meaning if within this file you utilize a require_once(../file.php); it will load the file accordingly. Whereas if you use the second route
/usr/bin/php -q /home/USER/public_html/cron/path-to-file.php
you must utilize absolute paths within your file. Including a file using a relative path (like ../) will throw an error, you must define the full path of the file. Save yourself a headache when you go to transfer hosts, utilize the first method.
Subscribe to:
Posts (Atom)

