Friday, 21 September 2018

Weird behaviour receiving a pdf content from a webservice

I have created a function that calls a web service for contents of pdf file. The webservice works good.

I guess the problem comes when the file is too large

/**
 * @param string $docId
 * @return string
 */
public function getDocumentFromDocId(string $docId)
{
    $client = new \nusoap_client('http://'.$this->ip.'/arcdoc/WebServiceServer.php?wsdl', true);
    $response = $client->call('GetDoc', array(
        'xxxx1' => 'xxxxxx',
        'xxxx2' => base64_encode('xxxxx'),
        'xxxx3' => base64_encode("yyyyyyy"),
        'xxxx4' => base64_encode($docId)
    ));
    var_dump($response);
    return $response;
}

When I var_dump() the content response this response:

/var/www/html/project/src/AppBundle/Service/whatever.php:55:string
'%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 3813>>
stream
x��ZMs�����JU�vSXVw�sn�G��$5��M �+�;���...'... (length=193068)

/var/www/html/project/src/AppBundle/Service/whatever.php:55:boolean false

There are actually like two var_dumps when it's actually only one as you can see.

It's like it's trying to put the content inside the variable string but fails and returns false.

When I return $response in the parent class false is returned.

If instead of using the var_dump function to see the $response I use the print_r function it prints all pdf until EOF. I also tried to download the pdf straight and compare the content from the print_r and the file and is the same content.

So, I can say that the webservice works good and must be something about php? I hope I'm not wrong.

Any idea about why I'm losing this content in the $response variable from php?

I were testing to reduce the same pdf from 9M to 6M and works good, so it must be something about the size of the file. In my case seems to start to work bad at 7-9M.

So, in all fail cases the content arrives to the php code but somehow it can no be assigned properly to the $response and when it get backs to the main function will always be false.



from Weird behaviour receiving a pdf content from a webservice

No comments:

Post a Comment