用swooleserver 开发业务程序,接收的数据比较大,需要保存到临时文件里,
当判断需要保存到文件时,创建临时文件,fopen打开文件,协程调度起作用了,
第二个数据包到了,这个包数据直接处理保存到临时文件,但是这时文件还没有打开?
if (!isset($this->cli_pool[$fd]['tmpfile']) || empty($this->cli_pool[$fd]['tmpfile'])){
$this->cli_pool[$fd]['tmpfile']=$this->get_tmp_mail_file();
$this->cli_pool[$fd]['fp']=fopen($this->cli_pool[$fd]['tmpfile'],"w");
if (!$this->cli_pool[$fd]['fp']){
throw new amException("Open tmp file fail".$this->cli_pool[$fd]['tmpfile']);
}
}
fwrite($this->cli_pool[$fd]['fp'],$this->cli_pool[$fd]['buffer'],$endflag+2); ***//此行报错"fp" 不存在***
这种情况,通常大家都是如何处理的?
用channel 每次连接创建一个 channel ,连接断开就释放是不是效率太低了,pop到会是绝对顺序的吗?
请高手给点建议
无法保证顺序,建议 单独开一个协程 $chan->pop,这个协程内首先 fopen 打开文件句柄。
然后所有 http request 请求全部进行 $chan->push()