一年多来,一直在没日没夜地研究计算机技术,只希望能多学一些东西能挣很多钱;一年过去了,工资还是没有涨,而我却成了计算机的奴隶,没有计算机将无法工作,没有计算机也就没有了乐趣,没有了计算机我会疯掉的。
除了多知道一些计算机的东西,我什么也不会;买东西只能去超市,和人打交道,我注定是要失败的。我只了解计算机,不了解人。我下一步要做的就是,少了解计算机,多了解人,多参加一些公共场合的活动,尽量里计算机远一些。
DevOps
一年多来,一直在没日没夜地研究计算机技术,只希望能多学一些东西能挣很多钱;一年过去了,工资还是没有涨,而我却成了计算机的奴隶,没有计算机将无法工作,没有计算机也就没有了乐趣,没有了计算机我会疯掉的。
除了多知道一些计算机的东西,我什么也不会;买东西只能去超市,和人打交道,我注定是要失败的。我只了解计算机,不了解人。我下一步要做的就是,少了解计算机,多了解人,多参加一些公共场合的活动,尽量里计算机远一些。
转自:http://baike.baidu.com/view/1068433.htm
内存泄漏
程序修改了之后,需要和以前的输出做比较,就是用了数组的求差函数array_diff() ,以前没用过,求出来的东西和我想要的不太一样,因为数组比较大,不太好看出问题,但是删除一部分之后,结果就正常了,终于在花费了3个小时的时间,发现了问题的所在;我渴望array_diff() 能比较key和value,而实际上它只比较了value,而不关心key,如果关心key的话,可以使用函数array_diff_assoc();
另外,php数组求交集的函数:
array_intersect — 计算数组的交集,只关心value,不关心key
array_intersect_assoc — 带索引检查计算数组的交集
出自诗经“知我者谓我心忧,不知我者谓我何求”,意思是知我的人呢说我正在心忧,不知我的人呢说我到底是为了什么呀。我不喜欢这个原创,更喜欢“知我者为我心忧,不知我者于我何求!”,当然这只是种理想主义状态,很多时候,我们经常忽视了别人,别人也常常没把自己当一回事。都是孤单的身影后寂聊的心情。
原诗:
彼黍离离,彼稷之苗。
行迈靡靡,中心摇摇。
知我者,谓我心忧;
不知我者,谓我何求。
悠悠苍天,此何人哉。
彼黍离离,彼稷之穗。
行迈靡靡,中心如醉。
知我者,谓我心忧;
不知我者,谓我何求。
悠悠苍天,此何人哉。
彼黍离离,彼稷之实。
行迈靡靡,中心如噎。
知我者,谓我心忧;
不知我者,谓我何求。
悠悠苍天,此何人哉。
下载地址:http://pecl.php.net/package/APC
配置详解:
apc.enabled can be set to 0 to disable APC. This is primarily useful when APC is statically compiled into PHP, since there is no other way to disable it (when compiled as a DSO, the extension line in php.ini can just be commented-out).
通过设置apc.enabled = 0 来禁用apc,这主要是当apc已经被静态编译到了php里了而又不想使用时很有用,因为没有其他的办法来禁用了
The number of shared memory segments to allocate for the compiler cache. If APC is running out of shared memory but you have already set apc.shm_size as high as your system allows, you can try raising this value. Setting this to a value other than 1 has no effect in mmap mode since mmap’ed shm segments don’t have size limits.(Default: 1)
这里设置可以使用多少个共享内存段,当一个共享内存段分配到系统允许的最大值还不够用时,就可以通过该项设置多个共享内存段,以增加缓存的大小;注意:使用mmap模式时,大于1的值是没有任何作用的,因为mmap的内存段是不受限制的;默认值为1
The size of each shared memory segment in MB. By default, some systems (including most BSD variants) have very low limits on the size of a shared memory segment.
设置每个共享内存段的大小,单位为MB
The optimization level. Zero disables the optimizer, and higher values use more aggressive optimizations. Expect very modest speed improvements. This is experimental.
设置优化级别,0为不优化,值越大,优化级别越高,但是如果代码写的不太好,优化级别太高,难免会出问题。
A "hint" about the number of distinct source files that will be included or requested on your web server. Set to zero or omit if you’re not sure; this setting is mainly useful for sites that have many thousands of source files.
应该是最多允许缓存多少个文件的意思,默认为1024个;(如果我翻译的有问题可以留言)
The number of seconds a cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry. Leaving this at zero means that your cache could potentially fill up with stale entries while newer entries won’t be cached.
如果缓存空间不够时,将清除缓存时间大于ttl(单位为:s)的一些cache来缓存新的文件,如果没有缓存时间大于ttl的cache或该ttl设置为0时,新的访问将不会被cache
The number of seconds that a cache entry may remain on the garbage-collection list. This value provides a failsafe in the event that a server process dies while executing a cached source file; if that source file is modified, the memory allocated for the old version will not be reclaimed until this TTL reached. Set to zero to disable this feature.
{不知道啥意思}
On by default, but can be set to off and used in conjunction with positive apc.filters so that files are only cached if matched by a positive filter.
默认缓存任何可以缓存的文件,如果设置为off,将根据apc.filter来缓存允许缓存的文件
A comma-separated list of POSIX extended regular expressions. If any pattern matches the source filename, the file will not be cached. Note that the filename used for matching is the one passed to include/require, not the absolute path. If the first character of the expression is a + then the expression will be additive in the sense that any files matched by the expression will be cached, and if the first character is a – then anything matched will not be cached. The – case is the default, so it can be left off.
是逗号分隔的正则表达式的列表,匹配的是文件名,后面的加号表示缓存,减号表示不缓存{现在没时间了,具体用法以后补充}
If compiled with MMAP support by using –enable-mmap this is the mktemp-style file_mask to pass to the mmap module for determing whether your mmap’ed memory region is going to be file-backed or shared memory backed. For straight file-backed mmap, set it to something like /tmp/apc.XXXXXX (exactly 6 Xs). To use POSIX-style shm_open/mmap put a .shm somewhere in your mask. e.g. /apc.shm.XXXXXX You can also set it to /dev/zero to use your kernel’s /dev/zero interface to anonymous mmap’ed memory. Leaving it undefined will force an anonymous mmap.
On very busy servers whenever you start the server or modify files you can create a race of many processes all trying to cache the same file at the same time. This option sets the percentage of processes that will skip trying to cache an uncached file. Or think of it as the probability of a single process to skip caching. For example, setting apc.slam_defense to 75 would mean that there is a 75% chance that the process will not cache an uncached file. So, the higher the setting the greater the defense against cache slams. Setting this to 0 disables this feature.
When you modify a file on a live web server you really should do so in an atomic manner. That is, write to a temporary file and rename (mv) the file into its permanent position when it is ready. Many text editors, cp, tar and other such programs don’t do this. This means that there is a chance that a file is accessed (and cached) while it is still being written to. This apc.file_update_protection setting puts a delay on caching brand new files. The default is 2 seconds which means that if the modification timestamp (mtime) on a file shows that it is less than 2 seconds old when it is accessed, it will not be cached. The unfortunate person who accessed this half-written file will still see weirdness, but at least it won’t persist. If you are certain you always atomically update your files by using something like rsync which does this correctly, you can turn this protection off by setting it to 0. If you have a system that is flooded with io causing some update procedure to take longer than 2 seconds, you may want to increase this a bit.
Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Normally you wouldn’t want to create, populate and tear down the APC cache on every CLI request, but for various test scenarios it is handy to be able to enable APC for the CLI version of APC easily.
安装:
tar xvf apc_x.y.tar
cd apc_x.y
./configure –enable-apc –enable-apc-mmap
make
make install
配置:
extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1
使用:
1. 源码里都有一个apc.php ,放到网站目录下,可以通过给文件知道apc的使用情况
转录某公司进行的PHP加速器性能比较报告:
Product / Test1 / Test2 / Test3
===========================
Reines PHP 5.1.4 / 100% / 100% / 100%
——————————————————
APC 3.0.10 / 112% / 409% / 145%
——————————————————
eAccelerator 0.9.5rc1 / 109% / 447% / 140%
——————————————————
Xcache 1.0.1rc1 / 119% / 95% / 111%
——————————————————
Zend Plattform 2.2.1 / 129% / 386% / 127%
——————————————————
首先郑重声明php不是必须以cgi方式运行才可以使用apd
所以手册里面的 Make sure you have installed the CGI version of PHP and it is available in your current path along with the phpize script.
有误导
首先去http://pecl.php.net/package/apd 下载对用的apd包
我下载的apd-1.0.1.tgz,没有找见win下的dll,不过有源码可以直接编译dll
解压缩
然后正常的 编译 安装 可以参考 xdebug部分的安装
配置php.ini
[apd]
;注意是zend_extension 不是extension,是绝对路径,不能是相对路径,手册上有说明,多看看手册在测试
zend_extension=/data/app/php/lib/php/extensions/no-debug-non-zts-20050922/apd.so
apd.dumpdir = /data/website/apd
apd.statement_tracing = 0
apd.dumpdir 是日志地址
这里需要注意的是
zend_extension 千万别 extension 否则
PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) ‘apd.so’ in Unknown on line 0
然后就可以做实验了
<?php
apd_set_pprof_trace();
XXXXX
?>
分析日志的方法 手册里这样写到
pprofp -R /tmp/pprof.22141.0
注意这里的pprofp 在你编译好的 apd的源码目录 其实就是一个php文件
这里你要修改pprofp文件开头的 php路径 才可以正常执行
php 以cgi方式运行的时候 据说 记着 -e参数 (看手册)
分析出来的结果 很帅吧
Trace for /XXXX.php
Total Elapsed Time = 0.54
Total System Time = 0.06
Total User Time = 0.13
Real User System secs/ cumm
%Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name
————————————————————————————–
100.0 0.00 0.54 0.00 0.13 0.00 0.06 1 0.0000 0.5362 0 main
100.0 0.00 0.54 0.00 0.13 0.00 0.06 1 0.0000 0.5362 0 apd_set_pprof_trace
98.7 0.04 0.53 0.01 0.12 0.00 0.06 14 0.0026 0.0378 0 require
83.4 0.00 0.45 0.00 0.10 0.00 0.04 1 0.0004 0.4471 0 DataProxy->run
61.1 0.33 0.33 0.02 0.02 0.00 0.00 5 0.0656 0.0656 0 DataProxy->getModule
10.1 0.00 0.05 0.00 0.03 0.00 0.02 1 0.0000 0.0542 0 MusicModule->onResponse
7.0 0.00 0.04 0.00 0.02 0.00 0.02 3 0.0003 0.0125 0 MusicModule->mr_param
6.8 0.04 0.04 0.02 0.02 0.02 0.02 3 0.0122 0.0122 0 MusicModule->mr_encrypt
5.8 0.00 0.03 0.00 0.02 0.00 0.01 1 0.0000 0.0308 0 NEWSModule->onResponse
5.3 0.00 0.03 0.00 0.01 0.00 0.00 1 0.0000 0.0286 0 Query->processRawQuery
5.0 0.03 0.03 0.02 0.02 0.01 0.01 193 0.0001 0.0001 0 Query->get
3.9 0.02 0.02 0.02 0.02 0.01 0.01 15 0.0014 0.0014 0 fetime
3.8 0.01 0.02 0.01 0.02 0.01 0.01 23 0.0006 0.0009 0 include
3.0 0.02 0.02 0.00 0.00 0.00 0.00 1 0.0161 0.0161 0 xml_iconv
2.6 0.01 0.01 0.00 0.00 0.00 0.00 32 0.0004 0.0004 0 html_substr
2.4 0.00 0.01 0.00 0.02 0.00 0.00 10 0.0000 0.0013 0 ModuleFactory->createModule
2.2 0.00 0.01 0.00 0.01 0.00 0.00 1 0.0000 0.0118 0 BlogModule->onResponse
1.4 0.00 0.01 0.00 0.00 0.00 0.00 1 0.0001 0.0077 0 MusicModule->get_rings
1.4 0.01 0.01 0.00 0.00 0.00 0.00 1 0.0075 0.0075 0 curl_fetch
1.1 0.00 0.01 0.00 0.00 0.00 0.00 5 0.0000 0.0012 0 add_tag_html_substr
世界上最远的距离
不是 生与死的距离
而是 我站在你面前
你不知道我爱你
世界上最远的距离
不是 我站在你面前
你不知道我爱你
而是 爱到痴迷
却不能说我爱你
世界上最远的距离
不是 我不能说我爱你
而是 想你痛彻心脾
却只能深埋心底
世界上最远的距离
不是 我不能说我想你
而是 彼此相爱
却不能够在一起
世界上最远的距离
不是 彼此相爱
却不能够在一起
而是明知道真爱无敌
却装作毫不在意
世界上最远的距离
不是 树与树的距离
而是 同根生长的树枝
却无法在风中相依
世界上最远的距离
不是 树枝无法相依
而是 相互了望的星星
却没有交汇的轨迹
世界上最远的距离
不是 星星之间的轨迹
而是 纵然轨迹交汇
却在转瞬间无处寻觅
世界上最远的距离
不是 瞬间便无处寻觅
而是 尚未相遇
便注定无法相聚
世界上最远的距离
是鱼与飞鸟的距离
一个在天,一个却深潜海底
The most distant way in the world
The most distant way in the world
is not the way from birth to the end.
it is when i sit near you
that you don’t understand i love u.
The most distant way in the world
is not that you’re not sure i love u.
It is when my love is bewildering the soul
but i can’t speak it out.
The most distant way in the world
is not that i can’t say i love u.
it is after looking into my heart
i can’t change my love.
The most distant way in the world
is not that i’m loving u.
it is in our love
we are keeping between the distance.
The most distant way in the world
is not the distance across us.
it is when we’re breaking through the way
we deny the existance of love.
So the most distant way in the world
is not in two distant trees.
it is the same rooted branches
can’t enjoy the co-existance.
So the most distant way in the world
is not in the being sepearated branches.
it is in the blinking stars
they can’t burn the light.
So the most distant way in the world
is not the burning stars.
it is after the light
they can’t be seen from afar.
So the most distant way in the world
is not the light that is fading away.
it is the coincidence of us
is not supposed for the love.
So the most distant way in the world
is the love between the fish and bird.
one is flying at the sky,
the other is looking upon into the sea.
交易之道,刚者易折。惟有至阴至柔,方可纵横天下。天下柔弱者莫如水,然上善若水。
成功,等于小的亏损,加上大大小小的利润,多次累积。做到不出现大亏损很简单,以生存为第一原则,当出现妨碍这一原则的危险时,抛弃其他一切原则。
因为,无论你过去曾经,有过多少个100%的优秀业绩,现在只要损失一个100%,你就一无所有了。交易之道,守不败之地,攻可赢之敌。100万亏损50%就成了50万,50万增值到100万却要盈利100%才行。
每一次的成功,只会使你迈出一小步。但每一次失败,却会使你向后倒退一大步。从帝国大厦的第一层走到顶楼,要一个小时。但是从楼顶纵身跳下,只要30秒,就可以回到楼底。
在交易中,永远有你想不到的事情,会让你发生亏损。需不需要止损的最简单方法,就是问自己一个问题:假设现在还没有建立仓位,是否还愿意在此价位买进。答案如果是否定,马上卖出,毫不犹豫。
逆势操作是失败的开始。不应该对抗市场,或尝试击败他。没有必要比市场精明。趋势来时,应之,随之。无趋势时,观之,静之。等待趋势最终明朗后,再动手也不迟。这样会失去少量的机会,但却赢得了资金的安全。你的目标必须与市场保持一致,顺应市场的趋势。如果你与市场保持一致,利润自会滚滚而来。如果你看错了趋势,就得使用古老而可靠的保护伞–止蚀单。这就是趋势和利润的关系。
操盘成功的两项最基本规则就是:停损和持长。一方面,截断亏损,控制被动。另一方面,盈利趋势未走完,就不轻易出场,要让利润充分增长。多头市场上,大多数股票可以不怕暂时被套。因为下一波上升会很快让人解套,甚至获利。这时候,买对了还要懂得安坐不动,不管风吹浪打,胜似闲庭信步。交易之道的关键,就是持续掌握优势。 快速认赔,是空头市场交易中的一个重要原则。当头寸遭受损失时,切忌加码再搏。在空头市场中,不输甚至少输就是赢。多做多错,少做少错,不做不错。在一个明显的空头市场,如果因为害怕遭受小损失而拒绝出局,迟早会遭受大损失。一只在中长期下降趋势里挣扎的股票,任何时候卖出都是对的。哪怕是卖在了最低价上。被动持有等待它的底部,这种观点很危险,因为它可能根本没有底。
学会让资金分批入场。一旦首次入场头寸发生亏损,第一原则就是不能加码。最初的损失往往就是最小的损失,正确的做法就是应该直接出场。如果行情持续不利于首次进场头寸,就是差劲的交易,不管成本多高,立即认赔。希望在底部或头部一次搞定的人,总会拿到烫手山芋。熊市下跌途中,钱多也不能赢。机构常常比散户死的难看。小资金没有战略建仓的必要,不需要为来年未知行情提前做准备。不需要和主力患难到底。明显下跌趋势中,20-30点的小反弹,根本不值得兴奋和参与。
有所不为才能有所为。行动多并不一定就效果好。有时什么也不做,就是一种最好的选择。不要担心错失机会,善猎者必善等待。在没有大机会的时候,要安静的如一块石头。交易之道在于,耐心等待机会,耐心等待最有利的风险/报酬比,耐心掌握机会。熊市里,总有一些机构,拿着别人的钱,即使只有万分之几的希望,也拼命找机会挣扎,以求突围解困。
我们拿着的是自己的钱,要格外珍惜才对。不要去盲目测底,更不要盲目炒底。要知道,底部和顶部,都是最容易赔大钱的区域。当你感到困惑时,不要作出任何交易决定。不需要勉强进行交易,如果没有适当的行情。没有胜算较高的机会,不要勉强进场。股市如战场,资金就是你的士兵。在大方向正确的情况下,才能从容地投入战斗。
要先胜而后求战,不能先战而后求胜。投机的核心就是尽量回避不确定走势,只在明显的涨势中下注。并且在有相当把握的行动之前,再给自己买一份保险(止损位摆脱出局),以防自己的主观错误。做交易,必须要拥有二次重来的能力,包括资金上,信心上和机会上。你可以被市场打败,但千万不能被市场消灭。我们来到这个市场是为了赚钱,但是这个市场却不是全自动提款机。
进入股市,就是要抢劫那些时刻准备抢劫你的人。股票投机讲究时机和技巧,机会不是天天有,即使有,也不是人人都能抓住。要学会分析自己擅长把握的机会,以己之长,攻彼之短。有机会就捞一票,没机会就观望,离开。如果自己都不清楚自己擅长什么,就不要轻举妄动。与鳄共泳有风险,入市捞钱需谨慎。
做交易,最忌讳使用压力资金。资金一旦有了压力,心态就会扭曲。你会因为市场上的正常波动而惊慌出局,以至事后才发现自己当初处于非常有利的位置。你也会因为受制于资金的使用时间,在没有机会的时候孤注一掷,最终满盘皆输。资金管理是战略,买卖股票是战术,具体价位是战斗。
在十次交易中,即使六次交易你失败了,但只要把这六次交易的亏损,控制在整个交易本金20%的损失内,剩下的四次成功交易,哪怕用三次小赚,去填补整个交易本金20%的亏损,剩下一次大赚,也会令你的收益不低。你无法控制市场的走向,所以不需要在自己控制不了的形势中浪费精力和情绪。不要担心市场将出现怎样的变化,要担心的是你将采取怎样的对策回应市场的变化。判断对错并不重要,重要的是当你正确时,你获得了多大的利润,当你错误的时候,你能够承受多少亏损。入场之前,静下心来多想想,想想自己有多少专业技能支撑自己在市场中拼杀,想想自己的心态是否可以禁得住大风大浪的起伏跌宕,想想自己口袋中有限的资金是否应付得了无限的机会和损失。炒股如出海,避险才安全。海底的沉船都有一堆航海图。最重要的交易成功因素,并不在于用的是哪一套规则,而在于你的自律功夫。
时间决定一切。人生并不只是谋略之争,某种程度上也是时间和生命的竞争。巴非特多活10年,每年哪怕只有5%的持续盈利,其财富的总增长,也足以笑傲天下。
什么是妻子?就是你愿意把积蓄交给她保管的女人。什么是情人?就是你偷偷摸摸地去和她约会又怕妻子撞见的女人。什么是红颜知己?就是你能把有些秘密说给她听却不能说给妻子听的女人。
妻子是一种约束,约束你不能随便和别的女人交往;情人是一种补偿,补偿你想从妻子那得到却又无法得到的激情;红颜知己就是一种点拨,点拨你心中的迷津。
妻子陪你过日子,情人陪你花钞票,红颜知己陪你聊聊天。妻子不能替代情人,因为她没有情人有情调;情人不能代替妻子,因为她没有妻子的亲情;妻子和情人都代替不了红颜知己,那是心灵的需要。
妻子是一个和你没有一点血缘关系的女人,却为你深夜不回家而牵肠挂肚;情人是一个和你没有一点家庭关系的女人,却让你尝尽做男人销魂滋味;红颜知己是一个还没和你扯上关系的女人,却能分担你的快乐和忧愁。
妻子是一个家,是一个能给你浮躁的心带来安抚的港湾;情人是家的累赘,只是不到万不得已你不想甩掉;红颜知己是家的点缀,没有她你不会觉得寂寞,但你会觉得生活没意思。
妻子的关心像一杯白开水,有时会成为一种唠叨,只是在生病时才成为一种温馨;情人的关心就像在白开水里加了一勺糖,慢慢地品上一个晚上还不满足;红颜知己的关心就像工作到午夜喝一杯咖啡,越喝越提神。
妻子怀上你的孩子会深情地问你想要个男孩还是要个女孩,情人怀上你的孩子会哭着来问你该怎么办怎么办啊?对于红颜知己,你会把你的情人怀孕的消息告诉她,并问她你该怎么办。至于妻子,你会在她发现你的情人肚子大了的秘密后才告诉她:“其实,我早就想告诉你了。”然后拼命地向她解释,并作可怜状。
妻子回了娘家一个星期不回来你也不想,情人三天不见你就给她打电话:“上哪去了?今晚我们到老地方喝杯咖啡好吗?”心中有了苦闷,你最想找个红颜知己倾诉,告诉她你在妻子和情人之间疲于奔命,实在受不了了。
最让男人受不了的是妻子的唠叨,情人的眼泪,红颜知己的误解。妻子的唠叨使男人的心乱上加乱,情人的眼泪让男人已硬的心变得酥软,红颜知己的误解把男人的心由悬崖推进深谷。
最好的妻子,就是男人能从她身上找到情人和红颜知己两种相互交织的感觉,只是这种感觉男人很难找到。最好的情人是在你和她的关系被妻子发现而主动退出又不提任何要求,只是情人很难做到这点。最好的红颜知己是有一天她能成为情人,甚至妻子,只是这种想法很难实现。
如果有可能,男人都在想把红颜知己变成情人,如果再有可能,再把她变成妻子。只是变成妻子的红颜知己就不再是知己了,因为很少有男人把自己的妻子当成知己的。男人心中有好多秘密不能随便说给妻子听。要不,那还叫男人么?
娶一个妻子是为了怕别人说闲话,找一个情人是为了给单调的生活加点味精,交一个红颜知己是想给空虚的心灵浇点鸡汤。男人一生都在寻找的不是一个妻子,也不是一个情人,而是一个甚至更多的红颜知己。
有些失去是注定的,有些缘分是永远不会有结果的,爱一个人不一定要拥有,但拥有了一个人就一定要珍惜,不要等到伤害的时候才去乞求原谅,不要等到失去的时候再去挽回。如果我不小心流下一滴泪水,那是因为我不愿意忘记你是谁。