随笔分类 -  php

1
摘要:/** * SnowFlake ID Generator * Based on Twitter Snowflake to generate unique ID across multiple * datacenters and databases without having duplicates. * * * SnowFlake Layout * * 1 sign ... 阅读全文
posted @ 2017-09-19 11:14 涛光 阅读(4641) 评论(0) 推荐(1)
摘要:以下是对信号量的处理函数,用于进程间通信(IPC)sem_acquire — Acquire a semaphoresem_get — Get a semaphore idsem_release — Release a semaphoresem_remove — Remove a semaphore$key=ftok(__FILE__,'t');$seg_id=sem_get($key); //获取一个信号idsem_acquire($seg_id); //取的信号//do somethingsem_release($seg_id); //释放信号量sem_remove($se 阅读全文
posted @ 2012-11-23 09:31 涛光 阅读(478) 评论(0) 推荐(0)
摘要:msg_get_queue — Create or attach to a message queuemsg_queue_exists — Check whether a message queue existsmsg_receive — Receive a message from a message queuemsg_remove_queue — Destroy a message queuemsg_send — Send a message to a message queuemsg_set_queue — Set information in the message queue dat 阅读全文
posted @ 2012-11-23 09:31 涛光 阅读(1036) 评论(0) 推荐(0)
摘要:以下是php的共享内存常用函数,用于进程间的通信shm_attach — Creates or open a shared memory segmentshm_detach — Disconnects from shared memory segmentshm_get_var — Returns a variable from shared memoryshm_has_var — Check whether a specific entry existsshm_put_var — Inserts or updates a variable in shared memoryshm_remove_ 阅读全文
posted @ 2012-11-23 09:31 涛光 阅读(1235) 评论(0) 推荐(0)
摘要:由于php的进程是不支持多线程的,有些场景为了方便以及提高性能,可以用php实现多进程以弥补这个不足:#!/usr/bin/env php<?php$cmds=array( array('/apps/bin/launcher.php','charge/promotion_props_stat.php','mobile',1), array('/apps/bin/launcher.php','charge/promotion_props_stat.php','mobile',2), array( 阅读全文
posted @ 2012-11-16 09:00 涛光 阅读(14500) 评论(1) 推荐(2)
摘要:最近一个后台常驻job通过redis的brpop阻塞读取消息时,设置的超时时间较长list($key,$row)=$redis->brPop($queue_name,3600); //超时时间为1小时但是在实际的使用中发现很短时间后就会退出,通过查看error log,发现:'RedisException' with message 'read error on connection' 提示经过一番折腾,原来发现是php.ini文件中的一个配置项导致:default_socket_timeout = 60由于redis扩展也是基于php 的socket方式 阅读全文
posted @ 2012-11-14 17:33 涛光 阅读(12690) 评论(0) 推荐(0)
摘要:shell:#!/bin/bash#==========================================================# this example show you how to get data from pipe#========================... 阅读全文
posted @ 2012-11-13 09:27 涛光 阅读(280) 评论(0) 推荐(0)
摘要:以下函数可用于替换php内置的is_writable函数//可用于替换php内置的is_writable函数function isWritable($filename){ if(preg_match('/\/$/',$filename)){ $tmp_file=sprintf('%s%s.tmp',$filename,uniqid(mt_rand())); return isWritable($tmp_file); } if(file_exists($filename)){ //文件已经存在的话,使用读写方式打开 $fp... 阅读全文
posted @ 2012-11-08 23:03 涛光 阅读(699) 评论(0) 推荐(0)
摘要:以下是通过php的socket扩展模块实现的一个简单的消息处理服务器端:绑定在一个本机的端口,监听客户端的连接,接收数据并转发给发送者之外的所有客户端socket_server.php#!/usr/bin/env php<?php//author:zhxiaif(!extension_loaded(... 阅读全文
posted @ 2012-10-29 18:19 涛光 阅读(1293) 评论(0) 推荐(0)
摘要:最近在使用php的mongo 扩展进行数据统计计算,其中有一个时间戳字段,由于精确到了毫秒,长度有13位,但由于开始的时候是以字符串的形式存储:{ "_id" : ObjectId("504eea97e4b023cf38e34039"), "in_ts" : NumberLong("1347349143699"), "log" : { "guid" : "4D1F3079-7507-F4B0-E7AF-5432D5D8229D", "p" 阅读全文
posted @ 2012-09-11 19:51 涛光 阅读(4128) 评论(0) 推荐(0)
摘要:cat get_pipedata.php#!/usr/bin/env php<?php#========================================================#testing how to get data from pipe#========================================================$fp=fopen('php://stdin','r');$result='';while(!feof($fp)){ $result.=fgets($fp,128) 阅读全文
posted @ 2012-08-14 10:46 涛光 阅读(2214) 评论(0) 推荐(0)
摘要:sudoapt-getinstallgccsudoapt-getinstallg++sudoapt-getinstallautoconfsudoapt-getinstalllibxml2sudoapt-getinstalllibxml2-devsudoapt-getinstalllibevent-1... 阅读全文
posted @ 2012-06-20 16:45 涛光 阅读(2957) 评论(0) 推荐(0)
摘要:一、安装Xcache#wgethttp://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz#tarzxvfxcache-1.3.0.tar.gz#cdxcache-1.3.0#/usr/local/php/bin/phpize#./configure--enable-xcache--enable-xcache-coverager--enable-xcache-optimizer--with-php-config=/usr/local/php/bin/php-config#make&&makeinstall 注 阅读全文
posted @ 2012-03-18 21:56 涛光 阅读(14994) 评论(2) 推荐(1)
摘要:官方网站:http://fallabs.com/安装 tokyocabinet./configure --prefix=/usr/local/tokyocabinet --enable-off64make && make install安装tokyotyrant./configure --prefix=/usr/local/tokyotryrant --with-tc=/usr/local/tokyocabinet/make && make install验证安装:在tokyotyrant-1.1.41下运行:#./ttservctl start#telnet 阅读全文
posted @ 2012-02-29 16:21 涛光 阅读(556) 评论(0) 推荐(0)
摘要:string iconv ( string $in_charset , string $out_charset , string $str )在使用这个函数进行字符串编码转换时,需要注意,如果将utf-8转换为gb2312时,可能会出现字符串被截断的情况发生。此时可以使用以下方法解决://author:zhxia [代码]即在第二个参数出添加红色字部分,表示:如果在目标编码中找不到与源编码相匹配... 阅读全文
posted @ 2010-11-18 10:38 涛光 阅读(800) 评论(0) 推荐(0)
摘要:[代码] 阅读全文
posted @ 2010-11-15 17:29 涛光 阅读(4361) 评论(1) 推荐(1)
摘要:wget http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gzsudo tar -xzvf xcache-1.3.0.tar.gzcd xcache-1.3.0sudo /usr/local/php-5.3.3/bin/phpize sudo ./configure --with-php-config=/usr/loca... 阅读全文
posted @ 2010-10-20 14:20 涛光 阅读(1621) 评论(0) 推荐(0)
摘要:#author:zhxia给php打上php-fpm 补丁sudo tar jxvf php-5.2.14.tar.bz2sudo patch -d php-5.2.14 -p1 < php-5.2.14-fpm-0.5.14.diff 编译phpcd php-5.2.14/sudo ./configure --prefix=/usr/local/php-5.2.14 --with-mcry... 阅读全文
posted @ 2010-09-18 09:10 涛光 阅读(2045) 评论(0) 推荐(0)
摘要://编译安装php 5.3.3#author:zhxia 由于php5.3.X已经自带了php-fpm所以不需要打补丁# sudo ./configure --prefix=/usr/local/php-5.3.3 --with-mcrypt --with-gettext --with-mysql --with-gd --with-jpeg-dir --with-png-dir --with-cu... 阅读全文
posted @ 2010-08-05 12:00 涛光 阅读(2328) 评论(0) 推荐(0)
摘要:/*获取图片新闻列表*/function getPicNews($number=5){ require_once 'include/content_class.php'; $Content=new Content(); $sql='select contentid as id,title,pic,typeid from `cms_content` where pic<>"" order... 阅读全文
posted @ 2010-06-12 16:18 涛光 阅读(330) 评论(0) 推荐(0)

1