Chinaunix

标题: why script stops after run 1025 times [打印本页]

作者: guishoudaoge    时间: 2009-08-07 14:35
标题: why script stops after run 1025 times
For visual code: http://paste2.org/p/364717



1. dont use mysql|memcache, the script will run and run, wont stop

2. use memcache, the script wont stop

3. use mysql, why such script will stop after run 1025 times and the error message is:

PHP Warning: shell_exec(): Unable to execute '/usr/bin/php /xxx/xxx/sites/xxx/web/application/data/scripts/report/test.php 1>>/tmp/haha 2>&1 & echo $!' in /xxx/xxx/sites/xxx/web/application/data/scripts/report/test.php on line 51

PHP Stack trace:

PHP 1. {main}() /mezi/mmweb/sites/revo/web/application/data/scripts/report/testReportScript.php:0



  1. <?php
  2. require 'header.php';

  3. try {
  4.    
  5. //    $frontendAdapter = 'Core';
  6. //    $frontendOptions = array('lifetime'    => 43200, 'automatic_serialization' => 1);
  7. //    $backendAdapter = 'Memcached';
  8. //    $backendOptions = array(
  9. //        'servers'    => array (
  10. //            array (
  11. //                 'host'    => 'xxxxx'
  12. //                ,'port'    => 11211
  13. //                ,'persistent' => 0
  14. //            )
  15. //        )
  16. //        ,'compression' => 0
  17. //    );
  18. //    $cache = Zend_Cache::factory($frontendAdapter, $backendAdapter, $frontendOptions, $backendOptions);
  19. //    $cache->load('hahah');
  20.         
  21.    
  22.    
  23.     $dbConfig = array(
  24.          'host'            => 'xxxx'
  25.         ,'username'        => 'username'
  26.         ,'password'        => 'password'
  27.         ,'dbname'        => 'dbname'
  28.     );
  29.     $gdsDb = Zend_Db::factory('PDO_MYSQL', $dbConfig->GDS->toArray());
  30.     $gdsDb->setFetchMode(Zend_Db::FETCH_OBJ);
  31.     $gdsDb->query('SET NAMES utf8');

  32. }catch (Exception $e) {
  33.     echo $e->getMessage() . "\n";
  34. }


  35. echo getcwd() . "\n";

  36. //sleep(1);

  37. try {
  38. $pid = shell_exec("php test.php 1>>/tmp/haha 2>&1 & echo $!");


  39. }catch (Exception $e) {
  40.    
  41.     echo $e->getCode() . "\n";
  42.     echo $e->getMessage() . "\n";
  43.     echo $e->getTraceAsString() . "\n";
  44.    
  45.     echo $pid . "\n";
  46.     echo "------";
  47.     $pid = shell_exec("php test.php 1>>/tmp/haha 2>&1 & echo $!");

  48.    
  49.    
  50. }
  51. ?>
复制代码

作者: ziggler    时间: 2009-08-07 16:05
有错误信息吗?
作者: guishoudaoge    时间: 2009-08-07 16:36
错误信息仅仅是

PHP Warning: shell_exec(): Unable to execute '/usr/bin/php /xxx/xxx/sites/xxx/web/application/data/scripts/report/test.php 1>>/tmp/haha 2>&1 & echo $!' in /xxx/xxx/sites/xxx/web/application/data/scripts/report/test.php on line 51

PHP Stack trace:

PHP 1. {main}() /mezi/mmweb/sites/revo/web/application/data/scripts/report/testReportScript.php:0
作者: ziggler    时间: 2009-08-07 16:37
对应行的代码那?
作者: guishoudaoge    时间: 2009-08-07 16:55
对应着这一行

try {
$pid = shell_exec("php test.php 1>>/tmp/haha 2>&1 & echo $!");






even havnt captured the Exception, dont know why .

[ 本帖最后由 guishoudaoge 于 2009-8-7 16:56 编辑 ]
作者: ziggler    时间: 2009-08-07 16:57
memcache 和这个有关系?1025是一个设置的值,如果不使用memcache;

你可以继续跟代码进去?
作者: guishoudaoge    时间: 2009-08-07 16:59
本来考虑是否是 OS在维护socket端口时做了限制,

所以考虑使用memcache进行测试,

测试没有限制。
作者: ziggler    时间: 2009-08-07 17:18
标题: 回复 #7 guishoudaoge 的帖子
关键是memcache的作用是啥?

另外代码是不是有些地方有设置?
作者: guishoudaoge    时间: 2009-08-07 17:43
memcache的作用就是为了对比数据库

memcache也是使用OS来维护socket连接,

其它方面没有另外的设置。
作者: ziggler    时间: 2009-08-07 17:46
标题: 回复 #9 guishoudaoge 的帖子
那看来是SOCKET连接维护的事情,没有东东维护,到一定程度就断了?

多试验几次,都是在1025次之后停下来了吗?
作者: guishoudaoge    时间: 2009-08-07 18:13
都是, 

can u try it in your env ?
作者: 网鬼    时间: 2009-08-07 22:24
$dbConfig = array(
         'host'            => 'xxxx'
        ,'username'        => 'username'
        ,'password'        => 'password'
        ,'dbname'        => 'dbname'
    );
    $gdsDb = Zend_Db::factory('PDO_MYSQL', $dbConfig->GDS->toArray());
这段代码是不是有点问题?
$dbConfig->GDS->toArray()
GDS到哪里来的呢?
作者: guishoudaoge    时间: 2009-08-07 23:09
dont care such details,  not such mistake can afford!
作者: 网鬼    时间: 2009-08-07 23:17
原帖由 guishoudaoge 于 2009-8-7 23:09 发表
dont care such details,  not such mistake can afford!

I'm very very sorry!
作者: guishoudaoge    时间: 2009-08-08 02:05
never mind, can u help me to do the same test.
作者: guishoudaoge    时间: 2009-08-08 02:10
原帖由 网鬼 于 2009-8-7 23:17 发表

I'm very very sorry!




never mind, can u help me to do the same test !
作者: geel    时间: 2009-08-11 14:39
有可能达到单用户执行进程的最大限制了。因为第一, shell_exec 的是自己,这样 test.php 始终作为父进程其某些操作可能不会退出。第二,shell执行的第二条语句 & echo $!,我想本意应该是 && echo吧,而程序里用了一个 &,这样就变成执行后挂起了,不知道跟这个有没有关系,手头没环境没法测试。

建议换一种方式试验一下,用另一个shell程序循环执行它,这样避免自己重复自己产生的进程问题。
作者: hbl.ncut    时间: 2009-08-11 16:55
是不是程序执行超出php进程得内存限制 ?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2