Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Request headers increased per call at client #10

Closed
jdomenechb opened this issue Dec 6, 2016 · 1 comment
Closed

Request headers increased per call at client #10

jdomenechb opened this issue Dec 6, 2016 · 1 comment

Comments

@jdomenechb
Copy link

Test case:

$jsonRpc = new \Zend\Json\Server\Client('http://server-url.com');
for ($i = 0; $i < 25000; $i++) {
    $jsonRpc->call('someMethod');
}

The method called in the server is a method that only returns hard-coded information, to avoid interferences.

Measuring the time the function spends proves that the time spent in the function gets increased at each request. After 20000+, the time spent by the call lasted more than 2.5 seconds.

send_times

I was able to isolate the issue to the merging of headers: in every request done the headers lasted more to be merged. After some analysis, I found out that he internal number of headers were being increased by two at every request.

headers_growing

The code that lead to this is: https://github.com/zendframework/zend-json-server/blob/master/src/Client.php#L121

        $headers = $httpRequest->getHeaders();
        $headers->addHeaders([
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ]);
        if (! $headers->get('User-Agent')) {
            $headers->addHeaderLine('User-Agent', 'Zend_Json_Server_Client');
        }

The headers are added independently of their existence. User-Agent is at least checking its existence before being added, so the solution would be to do the same with "Content-Type" and "Accept".

@digitronac
Copy link
Contributor

i believe this issue can be closed since it looks like that #6 resolved it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants