Browsing all articles tagged with PHP
3
0

在编译php-fpm0.6的时候需要注意的一些问题

Author Jessica     Category PHP     Tags , ,

也许大家都在用php-fpm0.5系列..其实php-fpm0.6早就发布了..并且再上次fix_pathinfo漏洞的时候.有人说过0.6不受这个漏洞的影响..

看来使用0.6还是还是有些必要的..

但是0.6比较起0.5来说..变化很大..代码上我不太清楚..但是从编译的步骤上来讲..确实有些我们需要注意的事情.

上次我曾经说过关于编译PHP5.2.12+php-fpm-0.6的问题..这次加上几个新的 就重新写一遍吧..

我这里就用php5.2.13和php-fpm-0.6~5.2.patch来打比方.

php-fpm需要autoconf2.13 所以我们需要先安装autoconf

1
2
3
4
5
6
7
# tar -zxvf autoconf-2.13.tar.gz
# cd autoconf-2.13
# ./configure --prefix=/usr/local/autoconf
# make
# make install
# export PHP_AUTOCONF=/usr/local/autoconf/bin/autoconf
# export PHP_AUTOHEADER=/usr/local/autoconf/bin/autoheader

另外还需要libevent-1.4.13-stable.tar.gz

read more

22
4

使用PHP将大文件导入到数据库中..

Author Jessica     Category PHP     Tags , , ,

朋友需要将一个有170w行的txt文件.按行把数据导入到数据库中..

所以我帮他写了一下 马克在这里 万一也有人用的着:)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
header ( "Content-type: text/html;charset=utf-8" );
set_time_limit(0);
include('Database.class.php');
$db = new Database('127.0.0.1', 'root', 'root', 'test'); //数据库
 
$fp = fopen('171w.txt', 'r'); //文件
$i=1; //开始行数
 
$array = array();  //用来存放从XXX-XXX行的数据的数组
 
//回调函数
function callback($now) {
	global $db, $array, $i, $fp;
    if(empty($array)) {             //为了节省资源..我们只生成一次数组
        while (!feof($fp)) {
           if($i == $now) {         //循环到需要读取的行数时
               for($j=$i;$j< =$i+999;$j++) {         //读取下面的1000行并存储到数组中
                   $array[$j] = stream_get_line($fp, 1000000, "\n");
               }
               break;
           }
           stream_get_line($fp, 1000000, "\n");    //实践证明 stream_get_line 比 fgets 快很多..
           $i++;
        }
    }
 
    $db->insert("INSERT INTO test(name) VALUES('{$array[$now]}')");  //插入到数据库中
}
 
 
include('SkiyoProcess.class.php');
 
$sp = new SkiyoProcess(2, 1000, 171000);  //间隔为2秒  每次插入1000条数据 一共171000行数据
$sp->process('callback');

需要的库 一起打包下载 没有提供那个文件 太大鸟..

read more

9
9

关于用PHP调用WebService中参数为complexType的问题

Author Jessica     Category PHP     Tags ,

今天在处理一个接口的时候,遇到一点问题。这个WebService中的一个方法的其中的一个参数是这个WebService中的另外一个方法..说起来很囧..

比如 这个WebService中有方法a跟b…但是a中的一个参数的类型是b的..而且a用到b的一些属性..

在WebService的XMl就被描述为tns:类型 并且另外一个方法为complexType类型..

一开始毫无头绪..后来搜索了下 加上自己的总结..终于解决..难点在于我们怎么用PHP去构造这么一个参数..

这个WebService的XML看起来是下面这样子的..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<s:element name="somefunc">
<s:complexType>
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="param1" type="s:string" />
    <s:element minOccurs="0" maxOccurs="1" name="param2" type="s:string" />
    <s:element minOccurs="0" maxOccurs="1" name="info" type="tns:info" />
  </s:sequence>
</s:complexType>
</s:element>
<s:complexType name="info">
<s:complexContent mixed="false">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="var1" type="s:string" />
    <s:element minOccurs="0" maxOccurs="1" name="var2" type="s:string" />
    <s:element minOccurs="0" maxOccurs="1" name="var3" type="s:string" />
    <s:element minOccurs="0" maxOccurs="1" name="var-4" type="s:string" />
  </s:sequence>
</s:complexContent>
</s:complexType>

其实很简单.用stdclass来构造一个含有这么多属性的对象即可..下面是我的代码.

read more

7
2

神奇的两次按位非运算符

Author Jessica     Category PHP     Tags ,

今天看到了James Padolsey的博客中谈到了连续进行两次按位非运算相当于floor的结果.

然后我进行了下测试,下面是我的代码:

1
2
3
4
5
6
7
8
9
10
11
$time = microtime(1);
for($i=0;$i< =100000;$i++) {
    ~~4.9;
}
echo microtime(1) - $time;
echo "<br>";
$time = microtime(1);
for($i=0;$i< =100000;$i++) {
    floor(4.9);
}
echo microtime(1) - $time;

这个在我机器的运行的结果是

0.013797998428345
0.041538000106812

我们可以看到 用~~几乎比floor快了三倍..

但是我们需要知道为什么~~就等价于floor了.

read more

19
9

goo.gl URL Shortener for WordPress

Author Jessica     Category PHP, 本站原创     Tags , , , ,

wp-goo.gl是一个可以使你的文章或评论中的链接转换为goo.gl短网址的一个WordPress插件。在文章中使用[goo.gl="名字"]链接[/goo.gl] 或者 [goo.gl]链接[/goo.gl] 会自动解析为goo.gl短网址,在评论中你不需要输入这些特定的标签,wp-goo.gl会自动将其转换为短网址。由于需要发出请求,所以你的服务器上必须开启cURL扩展!注意:这个插件将会永久性的更改你输入的链接!

wp-goo.gl allows you to publish links in your posts or comments using goo.gl short URL service. With [goo.gl="name"]link[/goo.gl] or [goo.gl]link[/goo.gl] in your posts. In comments, you donot have to write such special codes. wp-goo.gl will change the links automatically. The cURL functions must be available on your server. WARNING: This plug-in will permanently change your input link!

使用方法:

1.将wp-goo.gl目录传到你的wp-content\plugins下。
2.在后台开启wp-goo.gl。
3.发布文章的时候加入 [goo.gl="名字"]链接[/goo.gl] 或者 [goo.gl]链接[/goo.gl] 会自动解析为goo.gl短网址。
4.你可以在设置-wp-goo.gl中进行文章或者评论的设置!

== Installation ==

1. Upload `googl-url-shortener-for-wordpress` to the `/wp-content/plugins/` directory
2. Activate the plugin through the ‘Plugins’ menu in WordPress
3. Use [goo.gl="name"]link[/goo.gl] or [goo.gl]link[/goo.gl] in your posts.

请大家进行测试 如果有问题了直接给我留言或者发邮件 admin@skiyo.cn

If you have any questions, please email to me. admin@skiyo.cn

下载:

read more

18
5

PHP上传进度条深度解析

Author 54chen     Category PHP     Tags ,

前言:Hi,我不是坦克,我是54chen,受哥学社动力所托,传递技术文章一篇,供大家吃晚饭时边吃边看,加强消化。

随着互联网的发展,越来越多的技术开始注重用户体验,以人为本才是长久之道,于是在上传的时候,大家都不再满足一个单一的“浏览”按钮,纷纷推出了带上传进度条的功能。而作为解释型语言的PHP,如何做到对上传文件的检测,如何实现上传进度条以其背后的原理,54chen将在本文中一步步展开。

一. 实现篇

一般情况,用PHP实现上传进度条就下面两种方法:

1.APC扩展(作者是PHP的创始人,5.2后PHP已经加入APC扩展)

2.PECL扩展模块 uploadprogress

不论是APC还是uploadprogress,都需要编译源码,因为原有的PHP函数根本不可能读取到临时文件夹里的东西。下面来看如何使用以及关键的代码:

APC实现方法:

read more

16
8

Google短网址(goo.gl)服务类

Author Jessica     Category PHP, 本站原创     Tags , , , ,

是根据goo.gl URL Shortener的插件修改成PHP版本的..

不要问我有什么用…= =||

例子:

1
2
3
include('GoogleShorter.class.php');
$g = new GoogleShorter();
echo $g->getURL('http://www.skiyo.cn/');

下步打算开发一个wp的插件 这样你在发表文章和评论的时候发表的网址就可以自动变成短网址了:)

下载地址:

read more

14
1

TinyURL.class.php

Author Jessica     Category PHP     Tags , , ,

写了一个简单的,可以应付一些简单的项目了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
 * TinyURL生成类
 *
 * @link http://skiyo.cn
 * @author Jessica
 * @license MIT
 */
class TinyURL {
 
	/**
	 * 组成URL的大小写字母
	 * 
	 * @var array
	 */
	protected $alpha = array();
 
	/**
	 * 数组数量
	 * 
	 * @var int
	 */
	protected $count = 0;
 
	/**
	 * 构造器 生成URL数组
	 *
	 * @access public
	 */
	public function  __construct() {
		$this->alpha = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
		$this->count = count($this->alpha);
	}
 
	/**
	 * 通过数字生成唯一的URL
	 * 
	 * @param int $num
	 * @return string
	 */
	public function getURL($num) {
		$num = (int)$num;
		$url = '';
		while($num >= 1) {
			$url .= $num < $this->count ? $this->alpha[$num] : $this->alpha[$num%$this->count];
			$num = (int)($num)/$this->count;
		}
		$url =  strrev($url);
		return $url;
	}
}
 
/**
 * @example
 */
$t = new TinyURL();
for($i=1;$i<=10000;$i++) {
	echo $t->getURL($i). '<br />';
}
10
1

使用PHP处理大于2038年以后的日期

Author Jessica     Category PHP, 收集整理     Tags , ,

这个是从网上找到的..现在做个记号..以免以后可能遇到..

例子

1
2
3
4
5
6
include_once "/includes/date.class.php";
$date = new Date("March 20, 2039 11:30 PM");
echo $date->format("d-M-Y");
 
$date = new Date();
echo $date->format("M d, Y","2079/12/20 12:30:23");

下载:dateclass

转自:http://xwisdomhtml.com/dateclass.html

Demo:http://xwisdomhtml.com/dateclass-test.html

文档:http://xwisdomhtml.com/dateclass-doc.html

8
2

TinyURL设计方案

Author Jessica     Category PHP, 本站原创     Tags , ,

现在貌似TinyURL很火爆,也逐渐成为一种流行趋势。

对应于PHP版本的TinyURL也有一些算法,其实本质上来说是一种hash。

除此之外,还有另外一种TinyURL方案,类似于http://img.ly

其实这种设计是最简单的,没有使用hash,而是递增,这种的好处就是数据库可以无限扩展,并且不会重复。

我们可以想想一下,我们只用大小写字母来表示,如果三位的话,就可以存储52*52*52=140608的URL,如果是4位的话就成了52*52*52*52=7311616,这个数量是几何级增长,并且搜索速度非常快。

PS:如果你觉得这不够用的话,你还可以把数字加进去:)

我刚才测试了下,我新建了一个表:

1
2
3
4
5
6
7
CREATE TABLE IF NOT EXISTS `url` (
  `id` int(11) NOT NULL auto_increment,
  `tiny` char(10) character set utf8 collate utf8_bin NOT NULL default '',
  `url` text NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `tiny` (`tiny`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

注:使用utf8_bin是为了区分大小写。

然后我往表中添加了100w条数据,下面是我的算法,非常简单,还可以再优化:

read more

分类目录

最近文章

最近评论

文章索引模板

标签

.net AJAX button Comet CSS Discuz! DIV+CSS Flash Form Google HTML编辑器 IE8 Java JavaScript jQuery JSP md5 MySQLReback Oracle PHP php-fpm PNG Punny SkiyoTabs tab TagCloud Vista Web2.0 Windows7 上传 加密 变量 图标 本站原创 模板 模板引擎 源码 登录 短网址 石家庄 算法 编译 面向对象 魔术方法

链接表