<?php
/**
* 进行写锁定的测试
* 打开线程1
*/
require("file_lock.php");
$lock = new File_Lock(dirname(dirname(__FILE__)) . "/FileLock.lock");
/** 单个线程锁定的速度 1s 钟 3万次。 **/
/** 两个线程写,两万的数据 大概要 7s 钟*/
/** 一个线程写,一万的数据 大概要 3.9s 钟,居然两个文件同时写,要快一点*/
/** 不进行锁定,一个进程 写大概要 2.8s 钟,加锁是有代价的。 */
/** 不进行锁定,两个进程 分布不是很均匀,而且大多数都冲突 */
$lock->writeLock();
$lock->increment();
$lock->unlock();
while ($lock->get() < 2) {
usleep(1000);
}
sleep(1);
echo "begin to runing n";
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++)
{
$lock->writeLock();
$lock->increment(1);
$lock->unlock();
}
$t2 = microtime(true) - $t1;
echo $t2;
?>
php google 风格分页代码
php google 风格分页代码
public function showCtrlPanel_g($halfPer = 5) {
$re = <div class="pageMore">
<ul>
<li><span>.$this->lineCount.条</span></li>
<li><span>.$this->currentPage./.$this->pageCount.页</span></li>;
if($this->currentPage-$halfPer >1){
$re .= <li><a href=".$this->fileName.pageno=1"><span>1</span></a></li>;
if($this->currentPage-$halfPer*2 >1){
$re .= <li><a href=".$this->fileName.pageno=.($this->currentPage-$halfPer*2)."><span>...</span></a></li>;
}else{
$re .= <li><a href=".$this->fileName.pageno=1"><span>...</span></a></li>;
}
}
for ( $i = $this->currentPage - $halfPer,$i > 1 || $i = 1 , $j = $this->currentPage + $halfPer, $j < $this->pageCount || $j = $this->pageCount;$i <= $j ;$i++ )
{
$re .= $i == $this->currentPage
? <li class="linkOn"><a href=".$this->fileName.pageno=.$i."><span>.$i.</span></a></li>." "
: <li><a href=".$this->fileName.pageno=.$i."><span>.$i.</span></a></li>." ";
}
if($this->currentPage+$halfPer < $this->pageCount){
if($this->currentPage+$halfPer*2 < $this->pageCount){
$re .= <li><a href=".$this->fileName.pageno=.($this->currentPage+$halfPer*2)."><span>...</span></a></li>;
}else{
$re .= <li><a href=".$this->fileName.pageno=.$this->pageCount."><span>...</span></a></li>;
}
$re .= <li><a href=".$this->fileName.pageno=.$this->pageCount."><span>.$this->pageCount.</span></a></li>;
}
$re .=
</ul>
</div>;
return $re;
}
php 日期转换成日时截
php 日期转换成日时截
private function toTimeStamp ($dateTimeString = NULL) {
if (!$dateTimeString) {
$dateTimeString = time();
}
$numeric = ;
$add_space = false;
for($i=0;$i<strlen($dateTimeString);$i++) {
if(strpos(0123456789,$dateTimeString[$i])===false) {
if($add_space) {
$numeric .= ;
$add_space = false;
}
} else {
$numeric .= $dateTimeString[$i];
$add_space = true;
}
}
$numeric_array = explode( ,$numeric,6);
if(sizeof($numeric_array)<3 || ($numeric_array[0]==0 && $numeric_array[1]==0 && $numeric_array[2]==0)) {
throw new Exception($dateTimeString . is an invalid parameter, 5);
} else {
$result = mktime(intval($numeric_array[3]), intval($numeric_array[4]), intval($numeric_array[5]),
intval($numeric_array[1]), intval($numeric_array[2]), intval($numeric_array[0])) ;
}
return $result;
}
php 缓存文件入门程序
class PageCache {
/**
* @var string $file 缓存文件地址
* @access public
*/
public $file;
/**
* @var int $cacheTime 缓存时间
* @access public
*/
public $cacheTime = 3600;
/**
* 构造函数
* @param string $file 缓存文件地址
* @param int $cacheTime 缓存时间
*/
function __construct($file, $cacheTime = 3600) {
$this->file = $file;
$this->cacheTime = $cacheTime;
}
/**
* 取缓存内容
* @param bool 是否直接输出,true直接转到缓存页,false返回缓存内容
* @return mixed
*/
public function get($output = true) {
if (is_file($this->file) && (time()-filemtime($this->file))<=$this->cacheTime && !$_GET[nocache]) {
if ($output) {
header(location: . $this->file);
exit;
} else {
return file_get_contents($this->file);
}
} else {
return false;
}
}
/**
* 设置缓存内容
* @param $content 内容html字符串
*/
public function set($content) {
$fp = fopen($this->file, w);
fwrite($fp, $content);
fclose($fp);
}
}
php日期所在月的天数
php日期所在月的天数
public function daysOfMonth ($year=NULL,$month=NULL) {
if ($year===NULL) {
$year = $this->getPart(yy);
}
if ($month===NULL) {
$month = $this->getPart(mm);
}
if ($month==2)
{
if (($year % 4 == 0 && $year % 100 != 0) || $year %
php 图片处理类,缩略,水印
php 图片处理类,缩略,水印
class Image {
php mage2wbmp 函数
image2wbmp
(PHP 4中“= 4.0.5,PHP 5中)
image2wbmp - 输出图像浏览器或文件
报告错误描述
布尔image2wbmp($oimg[,$filename[,soruce]])
image2wbmp()输出或保存一个给定的图像WBMP版本。
报告错误参数
图片
图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。
文件名
路径保存的文件。如果没有给出原始图像流将被直接输出。
开始
阈值介于0和255(含)。
报告错误返回值
返回TRUE,成功或失败则返回FALSE。
报告错误的例子
php getimagesize
php getimagesize
getimagesize是读取图片相关信息,返回一个具有四个单元的数组。索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标
会员数据导入uchome程序实例
会员数据导入uchome程序实例
<?php
try {
$uc_db = new DataSource(UC_DBHOST , UC_DBUSER , UC_DBPW , UC_DBNAME,
php列出数据再用js 删除数据
php列出数据再用js 删除数据
<?php
include("../inc/inc.php");
islogin();
$Db = new Db();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>增加城市分类</title>
<!-- at:jimmy email:mailangel123@163.com -->
[原创]php数据库连接类
[原创]phpphp连接类
<?php
class Db{
public $conn;
public $root=localhost;
public $user=root;
public $pass=root;
public $db=111cn.cn;
public $charset=gb2312;
public $links=c;
function __construct() {
$this->connect();
}
function connect()
{
try{
if( p == $this->links )
{
$this->conn = php_pconnect($this->root,$this->user,$this->pass) or die(mysql_error());
}
else
{
$this->conn = mysql_connect($this->root,$this->user,$this->pass) or die( mysql_error());
}
mysql_select_db($this->db,$this->conn);
mysql_query("set Names $this->charset");
}catch (Exception $e){
echo 数据库连接失败,请联系相关人员!;
exit;
}
}
/*
query
*/
function query($sql)
{
$this->row = mysql_query( $sql,$this->conn ) or die( mysql_error());
return $this->row;
}
/*
mysql_num_rows total
*/
function rows($row)
{
return mysql_num_rows( $row );
}
/*
get data store array
*/
function fetch($row,$tag=1)
{
if(1 == $tag )
{
return mysql_fetch_array( $row );
}
else
{
$array =array();
while( $rs = mysql_fetch_array( $row ) )
{
$array[] = $rs;
}
}
return $array;
}
/*
取得刚插入的ID号
*/
function insert_id()
{
return @mysql_insert_id($this->row);
}
//close current database link
function close()
{
return @mysql_close($this->conn);
}
//test mysql version
function version()
{
$query = @mysql_query("SELECT VERSION()",$this->conn);
return @mysql_result($this->$row, 0);
}
}
?>
php 批量过滤post,get敏感数据
php 批量过滤post,get敏感数据
if (get_magic_quotes_gpc()) {
$_GET = striphplashes_array($_GET);
$_POST = stripslashes_array($_POST);
}