duannei0044 2010-08-05 03:17
浏览 7

是否有可能阻止zend引擎释放资源?

Is it possible to prevent zend engine to free resources allocated in PHP?

For example, when a process is forked() and the resource is duplicated to the child process, when either child process or parent process exit, the resource is free thus other processes can't access them any more.

  • 写回答

1条回答 默认 最新

  • douzhanglun4482 2011-03-30 18:44
    关注

    Freeing resourses is not the problem, because the parent and child have no access to each other's resourses. Maybe you are talking about mysql connection. The problem is that even if you don't call mysql_close() it's called by php. This is an example

    mysql_connect(...); 
    if(pcntl_fork()) exit();
    mysql_query( ... ); //no mysql connection here 
    

    I heard that parent can prevent this by killing itself with SIGKILL, but I haven't tested it. Should be something like:

    mysql_connect(...); 
    if(pcntl_fork()) {
      posix_kill ( posix_getpid() , SIGKILL);
      exit(); // won't hurt to leave it here
    }
    mysql_query( ... ); //no mysql connection here 
    

    Or if parent starts many children and they close connection to database on quit you can use the same approach on children.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大