dsoxcj7276 2019-06-28 13:37
浏览 131

SOAP请求非常慢

In my php website, whenever a user is saved a SOAP request is made to an external API through. This request takes a very long time, +20 seconds.
Trying to find the bottleneck I have put some logs and I see that the constructor is not the issue (0.0005 second), the actual call is.
Here is what my class looks like:

Myclass extends SoapClient
{
    public function __construct($wsdl = null, $options = array())
    {
        $start = microtime(true);
        parent::SoapClient($wsdl, $options);
        $end = microtime(true);
        // $end-$start = 0.0005s
    }

    public function sendUserData($userData)
    {
        $start = microtime(true);
        $result = $this->__soapCall('TriggerCampaign', array($userData));
        $end = microtime(true);
        // $end-$start = 24.77s
    }
}

On my local machine the __soapCall takes at the maximum 1 second, on test environment it takes about half a second and in production it takes up to 30 seconds. The constructor takes 0.0005 second on all the environments.

The external API says it doesn't come from their end.
From my microtime logging I believe it does.

Is it possible that they are right and there is something about my production environment that makes the request so slow?
How can I debug more in depth this matter in order to find the culprit?

edit
I remembered after posting that the external API has an alternate URL, so in order to determine if the problem is on my side or theirs, I made a quick and dirty script in which I make 2 SOAP calls to those 2 different URLs with the same data and executing the same method. The script looks like this:

<?php
$constructorStart1 = microtime(true);
$soapClient1 = new SoapClient('http://url1.com?WSDL');
$constructorEnd1 = microtime(true);

$header1 = array(
    'Login' => 'login1',
    'Password' => 'password1'
);
$headers1 = new SoapHeader('http://tempuri.org/', 'AutomationAuthHeader', $header1);
$soapClient1->__setSoapHeaders($headers1);

$args1 = array(
    'GateName' => 'UPDATE_MEMBER',
    'InputData' => array(
        //some values
    )
);

$callStart1 = microtime(true);
$soapClient1->__soapCall('TriggerCampaign', $args1);
$callEnd1 = microtime(true);

echo 'SOAP url: url1.com?WSDL' . "<br>";
echo 'SOAP construtor time: ' . number_format($constructorEnd1 - $constructorStart1, 4) . "<br>";
echo 'SOAP call time: ' . number_format($callEnd1 - $callStart1, 4) . "<br><br>";

$constructorStart2 = microtime(true);
$soapClient2 = new SoapClient('http://url2.com?WSDL');
$constructorEnd2 = microtime(true);

$header2 = array(
    'Login' => 'login2',
    'Password' => 'password2'
);
$headers2 = new SoapHeader('http://tempuri.org/', 'AutomationAuthHeader', $header2);
$soapClient2->__setSoapHeaders($headers2);

$args2 = array(
    'GateName' => 'UPDATE_MEMBER',
    'InputData' => array(
        //some value
    )
);

$callStart2 = microtime(true);
$soapClient2->__soapCall('TriggerCampaign', $args2);
$callEnd2 = microtime(true);

echo 'SOAP url: http://url2.com?WSDL' . "<br>";
echo 'SOAP construtor time: ' . number_format($constructorEnd2 - $constructorStart2, 4) . "<br>";
echo 'SOAP call time: ' . number_format($callEnd2 - $callStart2, 4) . "<br>";

The result I get is:

SOAP url: http://url1.com?WSDL
SOAP construtor time: 0.0004
SOAP call time: 0.1568

SOAP url: http://url2.com?WSDL
SOAP construtor time: 0.0002
SOAP call time: 22.1807

for me that is definitive proof that the slowness comes from their side, am I correct?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 fluent的在模拟压强时使用希望得到一些建议
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退