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

Request headers increased per call at client  #10

Closed
@jdomenechb

Description

@jdomenechb

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions