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

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

          <bdo id='T7Bwu'></bdo><ul id='T7Bwu'></ul>
        <tfoot id='T7Bwu'></tfoot>

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

      2. PHP 警告:exec() 无法分叉

        PHP Warning: exec() unable to fork(PHP 警告:exec() 无法分叉)

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

              <tfoot id='jfX9y'></tfoot>
                <tbody id='jfX9y'></tbody>
              • <bdo id='jfX9y'></bdo><ul id='jfX9y'></ul>

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

                  本文介绍了PHP 警告:exec() 无法分叉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以这里有一些关于我的设置的背景信息.使用 apache 和 php 5.2.17 运行 Centos.我有一个网站,列出了许多不同零售商网站的产品.我有爬虫脚本运行以从每个网站抓取产品.由于每个网站都不同,因此必须自定义每个爬虫脚本以爬取特定的零售商网站.所以基本上我每个零售商都有 1 个爬虫.此时我有 21 个爬虫,它们不断运行以从这些网站收集和刷新产品.每个爬虫都是一个 php 文件,一旦 php 脚本运行完毕,它会检查以确保它自己的唯一实例正在运行,并且在脚本的最后,它使用 exec 重新启动自己,同时原始实例关闭.这有助于防止内存泄漏,因为每个爬虫在关闭之前都会自行重启.但是最近我会检查爬虫脚本并注意到其中一个不再运行,并且在错误日志中我发现以下内容.

                  PHP 警告:exec() [<a href='function.exec'>function.exec</a>]: 无法 fork [nice -n 20 php -q/home/blahblah/crawler_script.php &gt;/dev/null &amp;]

                  这应该是重新启动这个特定爬虫的原因,但是由于它无法分叉"它从未重新启动,并且爬虫的原始实例像往常一样结束.

                  显然这不是权限问题,因为这 21 个爬虫脚本中的每一个在其运行结束时每 5 或 10 分钟运行一次此 exec 命令,并且大部分时间它都按应有的方式运行.这似乎每天发生一次或两次.似乎它是某种限制,因为自从我添加了第 21 个爬虫后,我才刚刚开始看到这种情况发生.而且它并不总是同一个爬虫得到这个错误,它会是随机时间中的任何一个无法分叉其重新启动执行命令的爬虫.

                  有没有人知道是什么导致 php 无法分叉,或者甚至是更好的方法来处理这些进程以一起解决错误?是否有我应该研究的过程限制或类似的东西?提前感谢您的帮助!

                  解决方案

                  进程限制

                  <块引用>

                  是否有我应该研究的进程限制"

                  怀疑有人(系统管理员?)设置了最大用户进程的限制.你能试试这个吗?

                  $ ulimit -a…………最大用户进程 (-u) 16384……

                  在 PHP 中运行前面的命令.类似的东西:

                  回显系统(ulimit -a");

                  我搜索了php.ini或httpd.conf是否有这个限制,但没有找到.

                  错误处理

                  <块引用>

                  甚至更好的方法来处理这些过程以一起解决错误?"

                  exec()的第三个参数返回$cmd的退出码.0 表示成功,非零表示错误代码.参考 http://php.net/function.exec .

                  exec($cmd, &$output, &$ret_val);如果 ($ret_val != 0){//在这里做事}别的{echo "成功
                  ";}

                  So here is a little background info on my setup. Running Centos with apache and php 5.2.17. I have a website that lists products from many different retailers websites. I have crawler scripts that run to grab products from each website. Since every website is different, each crawler script had to be customized to crawl the particular retailers website. So basically I have 1 crawler per retailer. At this time I have 21 crawlers that are constantly running to gather and refresh the products from these websites. Each crawler is a php file and once the php script is done running it checks to ensure its the only instance of itself running and at the very end of the script it uses exec to start itself all over again while the original instance closes. This helps protect against memory leaks since each crawler restarts itself before it closes. However recently I will check the crawler scripts and notice that one of them Isnt running anymore and in the error log I find the following.

                  PHP Warning:  exec() [<a href='function.exec'>function.exec</a>]: Unable to fork [nice -n 20 php -q /home/blahblah/crawler_script.php &gt;/dev/null &amp;]
                  

                  This is what is supposed to start this particular crawler over again however since it was "unable to fork" it never restarted and the original instance of the crawler ended like it normally does.

                  Obviously its not a permission issue because each of these 21 crawler scripts runs this exec command every 5 or 10 minutes at the end of its run and most of the time it works as it should. This seems to happen maybe once or twice a day. It seems as though its a limit of some sort as I have only just recently started to see this happen ever since I added my 21st crawler. And its not always the same crawler that gets this error it will be any one of them at a random time that are unable to fork its restart exec command.

                  Does anyone have an idea what could be causing php to be unable to fork or maybe even a better way to handle these processes as to get around the error all together? Is there a process limit I should look into or something of that nature? Thanks in advance for help!

                  解决方案

                  Process limit

                  "Is there a process limit I should look into"

                  It's suspected somebody (system admin?) set limitation of max user process. Could you try this?

                  $ ulimit -a
                  ....
                  ....
                  max user processes              (-u) 16384
                  ....
                  

                  Run preceding command in PHP. Something like :

                  echo system("ulimit -a");
                  

                  I searched whether php.ini or httpd.conf has this limit, but I couldn't find it.

                  Error Handling

                  "even a better way to handle these processes as to get around the error all together?"

                  The third parameter of exec() returns exit code of $cmd. 0 for success, non zero for error code. Refer to http://php.net/function.exec .

                  exec($cmd, &$output, &$ret_val);
                  
                  if ($ret_val != 0)
                  {
                      // do stuff here
                  }
                  else
                  {
                      echo "success
                  ";
                  }
                  

                  这篇关于PHP 警告:exec() 无法分叉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)

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

                    <bdo id='bbDxV'></bdo><ul id='bbDxV'></ul>

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

                        1. <legend id='bbDxV'><style id='bbDxV'><dir id='bbDxV'><q id='bbDxV'></q></dir></style></legend>

                          1. <tfoot id='bbDxV'></tfoot>
                              <tbody id='bbDxV'></tbody>