Cannot redeclare class的问题

xyzasd01

HTTP协议下,一个请求,较慢,大约10秒。在未结束时另一个请求来了,访问同一个文件。这个时候会出现Cannot redeclare class错误。

WORKER EXIT UNEXPECTED E_COMPILE_ERROR Cannot redeclare class Test in /private/var/www/workerman-chat/Applications/Chat/Web/login.php on line 3
worker exit with status 65280

3818 2 0
2个回答

walkor

可以利用自动加载机制避免这个问题。
或者用require_once加载你的类文件。

  • xyzasd01 2016-06-15

    WebServer.php:

                ob_start();
                // Try to include php file.
                try 
                {
                    // $_SERVER.
                    $_SERVER['REMOTE_ADDR'] = $connection->getRemoteIp();
                    $_SERVER['REMOTE_PORT'] = $connection->getRemotePort();
                    include $workerman_file;
                }
                catch(\Exception $e) 
                {
                    // Jump_exit?
                    if($e->getMessage() != 'jump_exit')
                    {
                        echo $e;
                    }
                }
                $content = ob_get_clean();
                ini_set('display_errors', 'on');
                $connection->close($content);

    在这里。

    访问localhost:55151/test.php的时候,第一个请求要10秒,再开第二个第三个,就会报错了。

walkor

http://doc3.workerman.net/advanced/webserver.html
如果要用workerman的webserver,先看看手册。

workerman是常住内存的,类不能重复加载。

开发http服务建议用nginx apache。workerman的目标是非http协议的应用。

  • 暂无评论
年代过于久远,无法发表回答
🔝