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

发布于 2024-09-12 13:34:05 字数 107 浏览 10 评论 0原文

是否可以阻止 zend 引擎释放 PHP 中分配的资源?

例如,当一个进程被forked()并且资源被复制到子进程时,当子进程或父进程退出时,资源是空闲的,因此其他进程不能再访问它们。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静谧 2024-09-19 13:34:05

释放资源不是问题,因为父级和子级无法访问彼此的资源。也许你说的是mysql连接。问题是,即使你不调用 mysql_close() 它也会被 php.ini 调用。这是一个例子,

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

我听说父级可以通过使用 SIGKILL 杀死自己来防止这种情况,但我还没有测试过。应该是这样的:

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

或者如果父进程启动了许多子进程,并且它们在退出时关闭了与数据库的连接,您可以对子进程使用相同的方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文