Tech Blog Using technology to help your business

11Dec/083

Update Delayed on Mysql and PHP

Wouldn't it be nice if we could use UPDATE DELAYED in mysql just like we do use INSERT DELAYED? Unfortunately, the work around mysql created for this is to insert a record into the events table in order to separate UPDATE statement into another thread. There is a large overhead to inserting to then execute an update.

If you are using PHP with mysql, there is another work around.  PHP has a function called, register_shutdown_function, which will execute a function during the shutdown of processing a script file. So if we add an UPDATE LOW_PRIORITY sql statement wrapped in a function that is passed to register_shutdown_function, we can allow the user to receive the page without delay while the UPDATE statement waits until all locks on the table has been release before proceeding.

function update_delayed()
{
$sql = "UPDATE LOW_PRIORITY table_name SET col1 = 'something'";
mysql_query($sql, $conn);
}

register_shutdown_function('update_delayed');

I wonder if there are even better ways to handle this problem.

19May/080

php strip_tags problem

I found that using php function, strip_tags, does not remove all the markup elements correctly from the subject content.  First of all, if an anchor link includes a line break, it will not be removed correctly.  Also, the style information is not properly removed as well.  In the following script, I also added in the regex to remove any content in between script tags, but that may or may not be necessary.

function strip_all_tags($content)
{
$content = preg_replace('/\n/',' ',$content);
$content = preg_replace('/<script.*<\/script>/U',' ',$content);
$content = preg_replace('/<style.*<\/style>/U',' ',$content);
$content = strip_tags(strtolower($content));
return $content;
}

The function will remove all line breaks so strip_tags will not have problems with finding all markups.  Since strip_tags does not remove <style> tags, the new function will remove them using regex.

Tagged as: , No Comments
   
Plugin from the creators of Brindes Personalizados :: More at Pazzani Technologies