Archive for the ‘php’ Category.

A custom Askimet implementation


If is true that the most you are popular the most you receive spam, we are getting real popular!
In the last weeks, we are receiving a lot of spam in the quotations comment system (which is open for everyone) on our main site.
We have also a lot of spam on our citaBlog (and only a little noise on this quite-unknow side blog) that we fight very well with the Askimet Wordpress plugin.
So, when the level of spam comments on our quotations archive went too high, we’ve looked for a way to use Askimet also with that not-on-a-blog spam.
A fast search let us find MicroAskimet, a simple php interface to use the Askimet service, available as a class or as standalone functions.
It took 15 minutes to code (using the standalone functions implementation) and it’s working perfectly: no more wasting time deleting spam comments!

Mike

A simple PHP time testing unit


It’s not a secret that we’re working on a new version (no new graphic) of our main site.
Adding a whole new section and a lot new features, we’re putting our hands on a big part of our code.
So we’ve started also to improve the overall performance of our site (written in php), optimizing the db queries and the php code itself.
To achieve this result we needed a simple way to check the timing behaviour of every section of our code.
There are some php testing unit out there, but we needed something more simpler and more usable.
So we’ve written our time testing unit, without using classes (I do like OO programming, but classes were unuseful for this simple target), in only one array and four functions.

Let’s see the code.
$ctk_timesteps=array();
 
function ctk_microtime_float()
{
   list($usec, $sec) = explode(” “, microtime());
   return ((float)$usec + (float)$sec);
}
 
function ctk_marktime($desc){
	global $ctk_timesteps;
	$ctk_timesteps[$desc]=ctk_microtime_float();
}
 
function ctk_start(){
	ctk_marktime(’start’);
}
 
function ctk_report(){
	ctk_marktime(‘final’);
	global $ctk_timesteps;
	$output=‘<div id="perftest" style="position:fixed;text-align:center;
		left:10px;top:10px;border:1px solid #b0b0b0;background-color:#e5efc9;
		padding:4px;z-index:100;color:#7b0000;">
		<b>Time Analysis</b> (sec)<br/>’;
	$total_time=$ctk_timesteps[‘final’]-$ctk_timesteps[’start’];
	$prevtime=$ctk_timesteps[’start’];
	
	foreach ($ctk_timesteps as $step => $steptime){
		if(($step!=’start’)&&($step!=‘final’)){
			$difftime=$steptime-$prevtime;
			$perctime=$difftime*100/$total_time;
			$output.=$step.‘: ‘.number_format($difftime,8).
				‘ (’.number_format($perctime,2).‘%)<br/>’;
			$prevtime=$steptime;
		}
	}
	$output.=‘Total time: ‘.number_format($total_time,8).‘</div>’;
	return $output;
}
 
//Start now!
ctk_start();

To use this unit, simply copy the code in a file and include it at the very first line of the php script you want to profile and then get your analysis report in a string rendered by the ctk_report() function.
To print it on the page, put an echo ctk_report() at the end of your file, but inside the body of the returned html page.
The results we’ll be displayed in a fixed div at the top left margin of your browser window.
We use the array $ctk_timesteps to store all the times we want to track. You can add a new timestep, inside your code, with the ctk_marktime('stepname') function, using a string as the stepname (that is printed on the report).
The unit will calculate all the times between the steps (with also the precentage).


Mike

March: the Month of PHP Bugs!


And so this is the Month of PHP Bugs!
Let’s see what will come out and we look forward for a strenghtened PHP in April. ;)

Mike

Another Wordpress release: 2.0.7!

Things are getting faster: another Wordpress release is out.
This in only a bugfix release due to a critical bug found in a core function of the php engine.
It’s good that the Wordpress Development Team has listed the few files that are changed, so the upgrade was fast.

Mike


And Wordpress 2.1 is aspected to arrive at the end of the month!

Speed up the Wordpress dashboard

The main page of the Wordpress admin dashboard loads three RSS feeds, that slows down the page loading and you don’t need to read at that moment.

The RSS feeds present in Wordpress 2.0.5 are: To disable those feeds you need to edit the index.php file in the wp-admin directory, commenting some lines.
Comment from line 18, that starts with:
$rss = @fetch_rss(‘http://feeds.technorati.com/cosm …  

to line 32, that is a single } after this html code:
</ul>
</div>

Then from line 127, that starts with:
php _e(“Below is the latest news from the official …  

to line 163, that is a single } before this html code:
<div style=“clear: both”>&nbsp;
<br clear=“all” />
</div>
</div>

Upload this modified file to your blog’s server and your dashboard will be fast as a lightning.

Mike