PHP线程异步调用php函数 [英] PHP threading call to a php function asynchronously
问题描述
我想要做的是异步地从数据库或内存缓存中加载一些数据.
What I'm looking to do is load in some data from a database or from memcache asynchronously.
我知道,我知道. "PHP不支持线程".
I know, I know. "PHP doesn't support threading".
但是register_tick_function呢?确实不是线程吗?
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?
推荐答案
PHP当然可以支持线程化.从SQL/NoSQL数据库并行加载数据绝对有可能.请参阅PHP手册,在github和pecl软件包中找到的示例,以及有关 http://pthreads.org
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安装pthreads,可以从pecl安装它(Windows incuded,dlls @ http ://windows.php.net/downloads/pecl/releases/pthreads ).抱歉.
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线程异步调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!