douwen1937 2015-04-17 02:50
浏览 46
已采纳

在HHVM下创建后台进程

I have a php script that I'd like to run in the background after the user submits a form. The simplest solution would seem to be to use a fork like the following:

$pid = pcntl_fork();
if ($pid) {
    // Parent process. Do nothing.
} else {
    // Child process. Put background script in this block.
}

This works well from the command line, but has been "disallowed" for browsers (HHVM can't use pcntl_fork).


The next simplest solution is to use

exec( 'php ' . $path . ' > /dev/null &' );

where $path would point to my background script. Again, this works perfectly on the command line, but when run from the browser it would produce the error

"Failed to initialize central HHBC repository: Failed to open file /var/www/.hhvm.hhbc"

I didn't even have a /var/www/ folder, so out of desperation I created one and symlinked the .hhvm.hhbc from /home/vagrant/.hhvm.hhbc into the new directory. I then got hit with a

"Failed to initialize central HHBC repository: Failed to initialize schema in /var/www/.hhvm.hhbc:"

I went a little crazy with chmod 777's throughout my html folder and on the original .hhvm.hhbc, but it did me no good.


It's a really bad user experience to run my background script in the foreground, because then there's a ~15 second pause after the submit button is clicked before the user can see the page again. Does anyone have an idea of how to do this?

  • 写回答

1条回答 默认 最新

  • dongyong1897 2015-04-17 03:08
    关注

    Try using "pagelets". This lets you spin up a new, background PHP request. Docs here: https://github.com/facebook/hhvm/blob/master/hphp/doc/threading

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上