PHP 线程异步调用 php 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13846192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:08:56  来源:igfitidea点击:

PHP threading call to a php function asynchronously

php

提问by Beachhouse

What I'm looking to do is load in some data from a database or from memcache asynchronously.

我想要做的是从数据库或从 memcache 异步加载一些数据。

I know, I know. "PHP doesn't support threading".

我知道我知道。“PHP 不支持线程”。

But what about register_tick_function? Isn't that indeed threading?

但是 register_tick_function 呢?那真的不是线程吗?

Has anyone done any kind of predictive preload or really any background processing utilizing register_tick_function?

有没有人使用 register_tick_function 做过任何类型的预测预加载或任何后台处理?

回答by Joe Watkins

http://php.net/pthreads

http://php.net/pthreads

http://docs.php.net/Thread

http://docs.php.net/Thread

PHP certainly can support threading. Loading data from a SQL/NoSQL database in parallel is definitely a possibility. See the PHP manual, examples found in github and pecl packages, and a little bit more info on http://pthreads.org

PHP当然可以支持线程。从 SQL/NoSQL 数据库并行加载数据绝对是可能的。请参阅 PHP 手册、github 和 pecl 包中的示例以及http://pthreads.org 上的更多信息

Please note, the documentation did state that this is part of the core, this is ( my ) human error. You must install pthreads with a thread-safe version of php, it can be installed from pecl ( windows incuded, dlls @ http://windows.php.net/downloads/pecl/releases/pthreads). Apologies.

请注意,文档确实说明这是核心的一部分,这是(我的)人为错误。您必须使用线程安全版本的 php 安装 pthreads,它可以从 pecl 安装(包括 windows,dlls @ http://windows.php.net/downloads/pecl/releases/pthreads)。道歉。