SoapServer 持久性随机失败

发布于 2024-10-31 04:30:26 字数 1454 浏览 2 评论 0原文

我已经制作了可以运行的 SOAP WSDL 服务。我添加了 2 个方法来测试 - 第一个 (setX($x)) 将 $this->x 设置为 $x,第二个 (getX()) 返回 $this->x。我的 SOAP 类的构造函数将 $this->x 设置为“FAIL”,而客户端代码调用 setX('SUCCESS')。

我添加了一些虚拟变量,使它们都是请求响应类型(单向似乎对某些客户端有一些奇怪的问题)。

好吧,它有效,客户端调用 $s->setX('SUCCESS') 和 $x = $s->getX(''),并且 $x = 'SUCCESS'。正如预期的那样。

但为了实现这一点,我必须对客户端使用以下选项:

'cache_wsdl' => WSDL_CACHE_MEMORY

为什么?它打败了我。对于其他所有选项,它都不起作用 - $x = 'FAIL' (无持久性)

好吧,它起作用了,那么问题是什么?有时,是的,有时它不起作用。该代码随机返回“失败”(因为持久性被破坏)。当它开始返回“失败”时,它会继续这样做。您可以启动另一个浏览器,它很可能会报告“成功”。

现在是最奇怪的部分。让我们使用一个浏览器。让我们重复以下步骤:启动浏览器,检查代码输出,直到返回“FAIL”。现在,按“Ctrl+R”大约 2 秒钟。突然间它就起作用了,现在每次都是“成功”!

搞什么?!!!我确实仔细检查了会议。每次创建 SoapServer 之前都会正确创建会话。每次调用 $server->setPersistence(SOAP_PERSISTENCE_SESSION) 时。而且它只在“大部分时间”起作用——这使得它完全没用!

有什么线索吗?

PS:我的服务WSDL已生成并缓存。我已将 sleep(1) 添加到 WSDL 生成器,并对客户端代码进行基准测试。它似乎不会重新生成 WSDL(以大约 10 毫秒结束 - 而不是 1010 毫秒)。使 WSDL 缓存无效(将 TTL 设置为 1)不会使持久性发挥作用,但在浏览器中愚蠢地按住 Ctrl+R 却可以!

PS2:WSDL 生成器、SOAP 类和测试客户端位于 3 个不同的文件中。 WSDL 类实际上启动服务器。它是从包含 SOAP 类 (index.php) 的文件中调用的。

PS3:我删除了 .htaccess ,它不应该破坏任何东西,我删除了一些未使用的文件和代码,然后繁荣 - 现在它每次都可以使用,任何类型的 wsdl_cache !好吧,我不知道那是什么,.htaccess?可能是 Apache 服务器内部问题。我无法再重现它了。如果您遇到类似的问题,我的建议是删除 .htaccess 并尝试重新启动 Apache。问题发生在清晨/深夜——我不确定,但我认为 cron 当时做了一些密集的备份任务。也许强制重新加载告诉 Linux 放松后台任务并为 Apache 和 PHP 投入更多资源 - 这可以解释奇怪的 Ctrl+R 行为。

更新:它仍然随机失败!大部分时间都有效,但我不能依赖这个功能。 (使用不同的服务、不同的客户端进行测试,但仍然是相同的服务器)。

I've made SOAP WSDL service which works. I've added 2 methods to test - the first one (setX($x)) sets $this->x to $x, second one (getX()) returns $this->x. The constructor of my SOAP class sets $this->x to 'FAIL', while client code calls setX('SUCCESS').

I've added some dummy variables to make them both request-response type (one-way seem to have some weird problems with some clients).

Well, it works, client calls $s->setX('SUCCESS') and $x = $s->getX(''), and $x = 'SUCCESS'. As expected.

But to achieve this, I had to use following option with client:

'cache_wsdl' => WSDL_CACHE_MEMORY

Why? It beats me. With every other option it just doesn't work - $x = 'FAIL' (no persistence)

OK, it works, so what's the problem? Sometimes, YES, SOMETIMES it doesn't work. The code randomly returns 'FAIL' (as persistence was broken). When it start to return 'FAIL' it keeps to do so. You can start another browser, and it will MOST PROBABLY report 'SUCCESS'.

Now the weirdest part. Let's use one browser. Let's repeat following steps: start the browser, check the code output until it returns 'FAIL'. Now, press 'Ctrl+R' for about 2 seconds. Suddenly it works, now it's 'SUCCESS' every time!

WTF?!!! I really double checked the session. Session is created properly before each time SoapServer is created. Each time $server->setPersistence(SOAP_PERSISTENCE_SESSION) is called. And it works only "most of the time" - which makes it completely useless!

Any clues?

PS: My service WSDL is generated and cached. I've added sleep(1) to WSDL generator, and benchmarked client code. It seems not to regenerate WSDL (ends in ca. 10ms - not 1010ms). Invalidating WSDL cache (with TTL set to 1) doesn't make persistence work, but stupid holding Ctrl+R in browser does!

PS2: WSDL generator, SOAP class and test client are in 3 different files. WSDL class actually starts the server. It's called from the file which contains SOAP class (index.php).

PS3: I removed .htaccess which should not break anything, I removed some unused files and code, and boom - now it works everytime, with any type of wsdl_cache! Well, I don't know what it was, .htaccess? Maybe Apache server internal problems. I cannot reproduce it anymore. If you experience similar problems, my advice is to drop .htaccess and try to restart Apache. The problems happened very early morning / late night - I'm not sure but I think cron does some intensive backup tasks at the time. Maybe compulsive reloading told Linux to relax with background tasks and put more resources to Apache and PHP - this would explain weird Ctrl+R behavior.

UPDATE: It still fails randomly! Works most of the time, but I can't rely on this feature. (Tested with different service, different client, but still the same server).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文