PHP+fork(): How to run a fork in a PHP code

前端 未结 3 1273
無奈伤痛
無奈伤痛 2021-02-04 19:41

I am running my code on CodeIgniter - Ubuntu Server.

I have been researching for async ways to run functions.

This is my function:



        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 20:06

    You must mention what's the operating system that you are using, because pcntl extensions are not available on Windows platform
    Also you must be aware that activating process control on Linux/Unix within a web server can give you unexpected results, so only CLI/CGI mode is recommended to use PCNTL
    Please read carefully this PCNTL Introduction

    Now, your code seems to be correct and well implemented, but you must compile your PHP with this option --enable-pcntl to enable pcntl functions like int pcntl_fork(void) otherwise you will get

    Fatal error: Call to undefined function pcntl_fork()

    For me, the best solution to run functions/methods in asynchronous way is to use pthreads, if you are interested by this advice i can edit my response by adding examples and how to install it on Windows or Linux platforms

    Read this article to know how to compile PHP

提交回复
热议问题