PCNTL函数族 PHP多进程编程
php有一组进程控制函数,使得php能在*nix系统中实现跟c一样的创建子进程、使用exec函数执行程序、处理信号等功能。
引用
Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment.
谨以此句献给超工,在web server环境中不要使用这组函数,因为会导致不可预料的结果。另,windows作为非类unix系统,没有这些函数。
PCNTL使用ticks来作为信号处理机制(signal handle callback mechanism),可以最小程度地降低处理异步事件时的负载。何谓ticks?Tick 是一个在代码段中解释器每执行 N 条低级语句就会发生的事件,这个代码段需要通过declare来指定。
PCNTL的函数都有这么些:
信号处理
int pcntl_alarm ( int $seconds )
设置一个$seconds秒后发送SIGALRM信号的计数器
bool pcntl_signal ( int $signo , callback $handler [, bool $restart_syscalls ] )
为$signo设置一个处理该信号的回调函数
下面是一个隔5秒发送一个SIGALRM信号,并由signal_handler函数获取,然后打印一个“Caught SIGALRM”的例子:
view plaincopy to clipboardprint?
<?php
declare(ticks = 1);
function signal_handler($signal) {
print "Caught SIGALRM\n";
pcntl_alarm(5);
}
pcntl_signal(SIGALRM, "signal_handler", true);
pcntl_alarm(5);
for(;;) {
}
?>
<?php
declare(ticks = 1);
function signal_handler($signal) {
相关文档:
$_GET 变量用于收集来自 method="get" 的表单中的值。
$_GET 变量
$_GET 变量是一个数组,内容是由 HTTP GET 方法发送的变量名称和值。
$_GET 变量用于收集来自 method="get" 的表单中的值。从带有 GET 方法的表单发送的信息,对任何人都是可见的(会显示在浏览器的地址栏),并且对发送的信息量也有限制(最多 100 个 ......
1.页面之间无法传递变量
get,post,session在最新的php版本中自动全局变量是关闭的,所以要从上一页面取得提交过来得变量要使用$_GET['foo'],$_POST['foo'],$_SESSION['foo']来得到。当然也可以修改自动全局变量为开(php.ini改为register_globals = On);考虑到兼容性,还是强迫自己熟悉新的写法比较好。
2.Win32 ......
<?php
/**
* PHP100.com - 个人感觉非常简单,只要有点PHP基础滴人都应该能看懂~~
* Apache2 + PHP5.0
* Version:1.0
* 同时感谢PHP100所有的兄弟们
* ——————————————&m ......
array_flip
交换数组中的键和值
$arr1 = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$array = array_flip($arr1);
showArr($array);
/*
Array
(
[1] => a
[2] => b
[3] => c
[4] => d
)
*/
array_key_exists
检查给定的键名或索引是否存在于数组中(也可用于对象 ......