Archive for March, 2008

MYSQL limit Optimization

select * from table LIMIT 5,10; #return to 6-15th line
select * from table LIMIT 5; #return to 0-5 line
select * from table LIMIT 0,5; #return to 0-5 line
 Performance optimization:
In MySQL5.0 limit high performance.
1.
Select * From cyclopedia Where ID>=(
Select Max(ID) From (
 Select ID From cyclopedia Order By ID limit 90001
) As tmp
) limit 100;
2.
Select * From [...]


Solar Form Validation Types

This is partially for my reference and partially for anyone looking at validating in their Solar_Form forms - here’s the validation methods (as defined in /Solar/Filter.php):
Each of these can be used when defining the form, commonly in the setElements structure like so:


Custom Form Helpers in Solar

Another thing that Solar makes easy is the creation of custom form helpers. These can be anything outside of the usual input types (like text, checkbox, textarea, etc) and can be used to make helpful, more complex inputs for your app.
In a previous post, I worked some with the Solar_Form class to create a login [...]


Being Binary in SOAP

Well, it might not be the best way to do it, but here’s a way I found to send binary data via PHP’s SOAP extension from one place to another:
Server:

?View Code PHPfunction recieveFile($data){
$data=base64_decode($data);
$path=’/my/file/path/img_out.gif’;
$fp=fopen($path,’w+’);
if($fp){ fwrite($fp,$data); fclose($fp); }
return strlen($data).’written’;
}
$input = file_get_contents(”php://input”);
$server = new SoapServer(’http://[my url here]/binary.wsdl’,array(’encoding’=>’ISO-8859-1′));
$server->addFunction(’recieveFile’);
$server->handle();

and the Client:

?View Code PHPini_set("soap.wsdl_cache_enabled", "0");
//send binary data
$client=new SoapClient(’http://[my url here]/binary.wsdl’,array(’encoding’=>’ISO-8859-1′));
$data=file_get_contents(’/my/file/path/img_to_send.gif’);
$ret=$client->recieveFile(base64_encode($data));
print_r($ret);
[/code]
 
It’s pretty [...]


Has optimized PHP click number statistics code

Has optimized PHP click number statistics code
< ?php
error_reporting(E_ALL);
$ROOT_PATH = ‘../’;
include_once($ROOT_PATH . “include/config.php”);$update_time = 1800;//The refresh time, second
$article_id = (isset($_GET['article_id']) && is_numeric($_GET['article_id']) && $_GET['article_id'] > 0) ? intval($_GET['article_id']) : 0;
if ($article_id > 0) {
    $filename = $ROOT_PATH . ‘log/click_log.txt’;


Simple yet powerfull PHP class to parse RSS.

<?php
/*
 ======================================================================
 lastRSS 0.9.1
 Simple yet powerfull PHP class to parse RSS files.
 by Vojtech Semecky, webmaster @ oslab . net
 Latest version, features, manual and examples:
     http://lastrss.oslab.net/
     http://www.easemarry.com/blog 
———————————————————————-
 LICENSE This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License (GPL)
 as published by the Free Software Foundation; either version 2
 of the [...]


Give Your Visitors a Rough Time

Toby Somerville recently blogged about giving visitors a rough time - instead of displaying exact timestamps, providing a rough written approximation of the time.
Toby suggested that we generally communicate in approximate times, but on the web work with exact timestamps. His idea was that by displaying the time as you would describe it verbally, he [...]


Debugging PHP code using debug_backtrace

Most of the PHP developers debug php code in their local machine just by trial and error using “print_r”,”var_dump” and “echo”. They dont write unit tests or follow any advanced debugger like xdebug. But the problem of using these methods is you cannot fool proof your code and their might be some bugs still present [...]


5 Ways to be a Better PHP Developer

Often, an inexperienced PHP developer will hop onto IRC and ask a question in ##php on Freenode. And if the question is trivial, the answer seems obvious or they simply seem like a newbie, they may soon find themselves bombarded with such comments as “RTFM”, “Go learn PHP”, “We are not your personal tutors” or [...]


The relative way transforms the absolute way

Withdraws in Gregarius a function. May turn into the homepage in relative way automatic extension the absolute way.
<?php
function relative_to_absolute($content, $feed_url) {
    preg_match(’/(http|https|ftp):\/\//’, $feed_url, $protocol);
    $server_url = preg_replace(”/(http|https|ftp|news):\/\//”, “”, $feed_url);
    $server_url = preg_replace(”/\/.*/”, “”, $server_url);
    if ($server_url == ”) {
        return $content;
    }
    if (isset($protocol[0])) {
        $new_content = preg_replace(’/href=”\//’, ‘href=”‘.$protocol[0].$server_url.’/’, $content);
        $new_content = preg_replace(’/src=”\//’, ’src=”‘.$protocol[0].$server_url.’/’, $new_content);
    [...]