在Windows上的PHP中进行分叉 [英] Forking in PHP on Windows

查看:79
本文介绍了在Windows上的PHP中进行分叉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Windows服务器上运行PHP(确实是许多问题的根源,但目前尚不能迁移).在某些情况下,用户启动的操作将需要启动一些需要一段时间的事情,而用户不需要知道这些事情是成功还是失败,例如发送电子邮件或确保执行某些操作.第三方帐户已更新.如果我可以使用pcntl_fork()进行分叉,这将非常简单,但是Windows无法使用PCNTL函数.

We are running PHP on a Windows server (a source of many problems indeed, but migrating is not an option currently). There are a few points where a user-initiated action will need to kick off a few things that take a while and about which the user doesn't need to know if they succeed or fail, such as sending off an email or making sure some third-party accounts are updated. If I could just fork with pcntl_fork(), this would be very simple, but the PCNTL functions are not available in Windows.

似乎我能得到的最接近的方法是做这种性质的事情:

It seems the closest I can get is to do something of this nature:

exec( 'php-cgi.exe somescript.php' );

但是,这将更加复杂.我需要开始的操作依赖于运行过程中已经存在的许多上下文.要使用上面的示例,我需要找出必要的数据,并以某种方式将其提供给新脚本.如果可以的话,那只是让父进程早日返回,而让孩子去做其他事情的问题.

However, this would be far more complicated. The actions I need to kick off rely on a lot of context that already will exist in the running process; to use the above example, I'd need to figure out the essential data and supply it to the new script in some way. If I could fork, it'd just be a matter of letting the parent process return early, leaving the child to work on a few more things.

我发现有一些人在谈论在Windows上编译各种PCNTL函数时在谈论自己的工作,但是似乎没有人可用(断开的链接等).

I've found a few people talking about their own work in getting various PCNTL functions compiled on Windows, but none seemed to have anything available (broken links, etc).

尽管这个问题与我的名字几乎相同,看来问题在于执行超时更多,而不是需要派生.因此,我最好的选择就是重构一下以处理调用php-cgi还是有其他选择?

Despite this question having practically the same name as mine, it seems the problem was more execution timeout than needing to fork. So, is my best option to just refactor a bit to deal with calling php-cgi, or are there other options?

看来exec()对此不起作用,至少在没有我弄清楚它的其他方面的情况下,因为它一直等到调用返回.我以为我可以使用START,有点像exec( 'start php-cgi.exe somescript.php' );,但是它仍然要等到其他脚本完成.

It seems exec() won't work for this, at least not without me figuring some other aspect of it, as it waits until the call returns. I figured I could use START, sort of like exec( 'start php-cgi.exe somescript.php' );, but it still waits until the other script finishes.

推荐答案

选项

how about installing psexec and use the -d (don't wait) option

exec('psexec -d php-cgi.exe somescript.php');

这篇关于在Windows上的PHP中进行分叉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆