<i id='jNqY6'><tr id='jNqY6'><dt id='jNqY6'><q id='jNqY6'><span id='jNqY6'><b id='jNqY6'><form id='jNqY6'><ins id='jNqY6'></ins><ul id='jNqY6'></ul><sub id='jNqY6'></sub></form><legend id='jNqY6'></legend><bdo id='jNqY6'><pre id='jNqY6'><center id='jNqY6'></center></pre></bdo></b><th id='jNqY6'></th></span></q></dt></tr></i><div id='jNqY6'><tfoot id='jNqY6'></tfoot><dl id='jNqY6'><fieldset id='jNqY6'></fieldset></dl></div>

      <legend id='jNqY6'><style id='jNqY6'><dir id='jNqY6'><q id='jNqY6'></q></dir></style></legend>
        <bdo id='jNqY6'></bdo><ul id='jNqY6'></ul>
      <tfoot id='jNqY6'></tfoot>

      <small id='jNqY6'></small><noframes id='jNqY6'>

    1. PHP 中的多线程

      Multi threading in PHP(PHP 中的多线程)
        <bdo id='gF851'></bdo><ul id='gF851'></ul>

            <small id='gF851'></small><noframes id='gF851'>

              <i id='gF851'><tr id='gF851'><dt id='gF851'><q id='gF851'><span id='gF851'><b id='gF851'><form id='gF851'><ins id='gF851'></ins><ul id='gF851'></ul><sub id='gF851'></sub></form><legend id='gF851'></legend><bdo id='gF851'><pre id='gF851'><center id='gF851'></center></pre></bdo></b><th id='gF851'></th></span></q></dt></tr></i><div id='gF851'><tfoot id='gF851'></tfoot><dl id='gF851'><fieldset id='gF851'></fieldset></dl></div>

                <tfoot id='gF851'></tfoot><legend id='gF851'><style id='gF851'><dir id='gF851'><q id='gF851'></q></dir></style></legend>
                  <tbody id='gF851'></tbody>
                本文介绍了PHP 中的多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 apcahe 服务器中,我想将 PHP 脚本作为 cron 运行,它会在后台启动一个 php 文件并在文件启动后立即退出,并且不等待脚本完成,因为该脚本需要大约 60 分钟才能完成完成.如何做到这一点?

                In a apcahe server i want to run a PHP scripts as cron which starts a php file in background and exits just after starting of the file and doesn't wait for the script to complete as that script will take around 60 minutes to complete.how this can be done?

                推荐答案

                你应该知道 PHP 中没有线程.但是,如果您在 Unix/linux 系统上运行,则可以轻松地执行程序并分离它们.

                You should know that there is no threads in PHP. But you can execute programs and detach them easily if you're running on Unix/linux system.

                $command = "/usr/bin/php '/path/to/your/php/to/execute.php'";
                exec("{$command} > /dev/null 2>&1 & echo -n $!");
                

                可以完成这项工作.让我们解释一下:

                May do the job. Let's explain a bit :

                exec($command); 
                

                Executes/usr/bin/php '/path/to/your/php/to/execute.php' : 您的脚本已启动,但 Apache 将在执行下一个代码之前等待执行结束.

                Executes /usr/bin/php '/path/to/your/php/to/execute.php' : your script is launched but Apache will awaits the end of the execution before executing next code.

                > /dev/null
                

                会将标准输出(即您的回显、打印等)重定向到一个虚拟文件(写入其中的所有输出都将丢失).

                will redirect standard output (ie. your echo, print etc) to a virtual file (all outputs written in it are lost).

                2>&1
                

                将错误输出重定向到标准输出,写入同一个虚拟和不存在的文件中.这避免了例如登录到您的 apache2/error.log.

                will redirect error output to standard output, writting in the same virtual and non-existing file. This avoids having logs into your apache2/error.log for example.

                &
                

                在您的情况下是最重要的事情:它会分离您对 $command 的执行:因此 exec() 将立即释放您的 php 代码执行.

                is the most important thing in your case : it will detach your execution of $command : so exec() will immediatly release your php code execution.

                echo -n $!
                

                将提供分离执行的 PID 作为响应:它将由 exec() 返回并让您能够使用它(例如,将此 pid 放入数据库并在一段时间后将其杀死以避免僵尸).

                will give PID of your detached execution as response : it will be returned by exec() and makes you able to work with it (such as, put this pid into a database and kill it after some time to avoid zombies).

                这篇关于PHP 中的多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <bdo id='jmUbm'></bdo><ul id='jmUbm'></ul>
                • <small id='jmUbm'></small><noframes id='jmUbm'>

                  • <legend id='jmUbm'><style id='jmUbm'><dir id='jmUbm'><q id='jmUbm'></q></dir></style></legend>

                    <i id='jmUbm'><tr id='jmUbm'><dt id='jmUbm'><q id='jmUbm'><span id='jmUbm'><b id='jmUbm'><form id='jmUbm'><ins id='jmUbm'></ins><ul id='jmUbm'></ul><sub id='jmUbm'></sub></form><legend id='jmUbm'></legend><bdo id='jmUbm'><pre id='jmUbm'><center id='jmUbm'></center></pre></bdo></b><th id='jmUbm'></th></span></q></dt></tr></i><div id='jmUbm'><tfoot id='jmUbm'></tfoot><dl id='jmUbm'><fieldset id='jmUbm'></fieldset></dl></div>

                        <tfoot id='jmUbm'></tfoot>
                            <tbody id='jmUbm'></tbody>