php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48216 PHP Fatal error: SOAP-ERROR: Parsing WSDL: Extra content at the end of the doc
Submitted: 2009-05-09 23:12 UTC Modified: 2011-11-23 10:50 UTC
Votes:116
Avg. Score:4.6 ± 0.8
Reproduced:109 of 110 (99.1%)
Same Version:53 (48.6%)
Same OS:26 (23.9%)
From: mark at everytruckjob dot com Assigned: dmitry
Status: Closed Package: SOAP related
PHP Version: 5.3.0RC2 OS: CentOs 5.3
Private report: No CVE-ID:
 [2009-05-09 23:12 UTC] mark at everytruckjob dot com
Description:
------------
Trying to set up a soapClient using the wsdl from the location found in http://www.everytruckjob.com/php53-url.txt (this contains the url and is not the wsdl file itself so I can remove the location once this report is closed as it is not my soap server).

Copying the wsdl from the referenced location to my own (http://www.everytruckjob.com/wsdl.php) or saving it to a local file allows parsing to succeed, but while the file sizes seem to be the same, I can't figure out what headers or content causes the "Extra content at the end of the document" error.

This works as expected on php 5.2.9 compiled and in use on the same client server with Centos 5.3 libxml2.x86_64 2.6.26-2.1.2.7.


Reproduce code:
---------------
<?php
$wsdl = trim(file_get_contents('http://www.everytruckjob.com/php53-url.txt'));   
try {
    $a = new SoapClient($wsdl);
} catch (SoapFault $e) {
    var_dump(libxml_get_last_error());
    var_dump($e);
}
?>

Expected result:
----------------
No SoapFault

Actual result:
--------------
object(LibXMLError)#1 (6) { ["level"]=>  int(3) ["code"]=>  int(5) ["column"]=>  int(4) ["message"]=>  string(41) "Extra content at the end of the document " ["file"]=>  string(55) "http://XXXX" ["line"]=>  int(488) } 

object(SoapFault)#2 (9) {
["message":protected]=>  string(146) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'XXXXX' : Extra content at the end of the document " 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-24 10:23 UTC] sjoerd-php at linuxonly dot nl
Thank you for your bug report.

The WSDL URL you supply does not send a Content-Length or Transfer-Encoding header in some cases, which is mandatory in a response with a body. In other words, it does not follow the HTTP protocol. You should contact the provider of the WSDL about this.


GET /url HTTP/1.0
Host: example.com

HTTP/1.1 200 OK
Date: Wed, 24 Jun 2009 10:18:10 GMT
Server: Apache
Connection: close
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?>...
 [2009-09-07 00:43 UTC] michael dot tibben at gmail dot com
We are experiencing a similar issue. However, the HTTP reply is using chunked transfer encoding (Content-Length is NOT required when using chunked)


HTTP/1.1 200 OK
Date: Sun, 06 Sep 2009 23:25:16 GMT
Server: Apache
X-Powered-By: Servlet/2.4 JSP/2.0
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8
 [2009-09-07 20:04 UTC] sjoerd@php.net
Thank you for your feedback.

It would be most helpful to us if you could supply us with the HTTP transaction of the retrieval of the WSDL. You may use a sniffer like Wireshark to obtain this information, or use this script I wrote <http://www.gissen.nl/files/sniff.php>.
 [2009-09-18 16:39 UTC] boris dot t at usask dot ca
it seems that X-Powered-By: is causing problems. 
The same problem exists when 

HTTP/1.x 200 OK
Date: Fri, 18 Sep 2009 16:24:06 GMT
X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0
Content-Type: text/xml;charset=utf-8
Connection: close
Transfer-Encoding: chunked
 
and the same code works when 

HTTP/1.x 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Fri, 18 Sep 2009 16:23:28 GMT
 [2009-10-06 17:09 UTC] robert dot ripley at fhchs dot edu
I'm also experiencing the same problem. Here is the HTTP header of the WSDL:

HTTP/1.1 200 OK\r\n
Date: Tue, 06 Oct 2009 16:48:26 GMT\r\n
Server: Apache/2.2.8 (Win32) PHP/5.2.5\r\n
X-Powered-By: PHP/5.2.5\r\n
Expires: Wed, 06 Oct 2010 04:00:00 GMT\r\n
Cache-Control: no-store, no-cache, must-revalidate\r\n
Pragma: no-cache\r\n
Last-Modified: Tue, 06 Oct 2009 16:48:26 GMT\r\n
Cache-Control: post-check=0, pre-check=0\r\n
Vary: User-Agent\r\n
Keep-Alive: timeout=5, max=100\r\n
Connection: Keep-Alive\r\n
Transfer-Encoding: chunked\r\n
Content-Type: application/xml;\r\n
\r\n
 [2009-10-07 18:29 UTC] Sjoerd@php.net
I tested using the HTTP trace Robert Ripley sent. I discovered some things:

Libxml uses the PHP stream wrappers to load the WSDL. These stream wrappers return a malformed WSDL to libxml. This is not specific to SOAP. Running file_get_contents($wsdl) also returns a malformed WSDL.

It is reproducible with PHP 5.3 but not with PHP 5.3-HEAD. This suggests that this bug has already been fixed.
 [2009-10-07 18:31 UTC] Sjoerd@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-10-15 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-10-30 15:04 UTC] nadavkav at gmail dot com
similar issue, on Debian unstable , PHP/5.3.0-3

laptop:/var/www/moodle-weekly/wspp/clients# ./mkclasses.sh
PHP Notice:  Undefined offset: 2 in /var/www/moodle-
weekly/wspp/wsdl2php.php on line 84
PHP Notice:  Undefined offset: 2 in /var/www/moodle-
weekly/wspp/wsdl2php.php on line 85
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 
'http://localhost/moodle-weekly/wspp/wsdl_pp.php' : Extra content at 
the end of the document
 in /var/www/moodle-weekly/wspp/wsdl2php.php on line 88
SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load 
from 'http://localhost/moodle-weekly/wspp/wsdl_pp.php' : Extra content 
at the end of the document
 in /var/www/moodle-weekly/wspp/wsdl2php.php:88
Stack trace:
#0 /var/www/moodle-weekly/wspp/wsdl2php.php(88): SoapClient-
>SoapClient('http://localhos...')
#1 {main}laptop:/var/www/moodle-weekly/wspp/clients#
 [2009-10-30 15:04 UTC] nadavkav at gmail dot com
similar issue, on Debian unstable , PHP/5.3.0-3

laptop:/var/www/moodle-weekly/wspp/clients# ./mkclasses.sh
PHP Notice:  Undefined offset: 2 in /var/www/moodle-
weekly/wspp/wsdl2php.php on line 84
PHP Notice:  Undefined offset: 2 in /var/www/moodle-
weekly/wspp/wsdl2php.php on line 85
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 
'http://localhost/moodle-weekly/wspp/wsdl_pp.php' : Extra content at 
the end of the document
 in /var/www/moodle-weekly/wspp/wsdl2php.php on line 88
SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load 
from 'http://localhost/moodle-weekly/wspp/wsdl_pp.php' : Extra content 
at the end of the document
 in /var/www/moodle-weekly/wspp/wsdl2php.php:88
Stack trace:
#0 /var/www/moodle-weekly/wspp/wsdl2php.php(88): SoapClient-
>SoapClient('http://localhos...')
#1 {main}laptop:/var/www/moodle-weekly/wspp/clients#
 [2009-11-17 10:37 UTC] dmitry dot dulepov at gmail dot com
Same issue on PHP 5.3 that comes with Mac OS X:

Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 
'http://typo3.org/wsdl/tx_ter_wsdl.php' : Extra content at the end of 
the document in /Users/user/Projects/TYPO3/typo3_src-
4.2.6/typo3/mod/tools/em/class.em_soap.php on line 115
 [2009-11-23 19:04 UTC] ondra dot podolinsky at seznam dot cz
The same problem: win xp, php 5.3.0.
[faultstring] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webapi.allegro.pl/uploader.php?wsdl' : Extra content at the end of the document [faultcode] => WSDL
 [2009-12-02 16:29 UTC] php dot net at drsdre dot org
Had the same issue with PHP 5.3.0. Content-lenght was available in the header, but PHP gace fatel error 'extra content at the end of the document'.

With php-5.3-win32-VC6-x85-latest.zip the WSDL is being read without problems.
 [2009-12-13 19:05 UTC] felipe@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-12-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-01-08 20:02 UTC] mike at pixor dot net
I downloaded the 1/6/10 5.3.3-dev snapshot and was still having issues 
with SOAP WSDL file parsing.  5.2.12 works fine.  Please keep this issue 
open.
 [2010-01-11 15:46 UTC] mike dot hall at twistdigital dot co dot uk
I'm having the same issue, also using chunked-encoding.

Date: Mon, 11 Jan 2010 15:44:23 GMT

Last-Modified: Fri, 09 Oct 2009 13:49:56 GMT

Accept-Ranges: bytes

Content-Type: text/xml

Cache-Control: private

Content-Encoding: gzip

Transfer-Encoding: chunked
 [2010-04-01 01:11 UTC] roy dot laurie at gmail dot com
Verified in 5.3.2 against the Yahoo! EWS service.
 
HTTP/1.1 200 OK
Date: Wed, 31 Mar 2010 23:04:51 GMT
p3p: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
Connection: close
Transfer-Encoding: chunked
Content-Type: text/xml;charset=utf-8

PHP 5.3.2 (cli) (built: Mar  5 2010 15:08:05)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with eAccelerator v0.9.6, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
    with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
 [2010-04-01 01:33 UTC] roy dot laurie at gmail dot com
Also, this is the current workaround that I'm using to get around this:

//+ral HACK: v5.3.x / libxml - http://bugs.php.net/bug.php?id=48216
//- $soapClient = new SoapClient("{$serviceUri}?wsdl", $soapOptions);
$tmpWsdlPath = tempnam(sys_get_temp_dir(), 'wsdl');
copy("{$serviceUri}?wsdl", $tmpWsdlPath);
$soapClient = new SoapClient($tmpWsdlPath, $soapOptions);
 [2010-04-29 19:08 UTC] eaf at oyatel dot no
Wow, this is bad, still not fixed in PHP 5.3.2.
Can this please be fixed for PHP 5.3.3?
 [2010-04-30 03:48 UTC] aharvey@php.net
-Status: No Feedback +Status: Open
 [2010-07-27 13:17 UTC] derek dot ethier at humber dot ca
I'm experiencing the same issue with the following WSDL file:

https://qa.everbridge.net/ws3/services/WebServices3?wsdl

I'm using 5.2.13 on Windows Server 2008.

Here is the XML parsing error:

object(LibXMLError)#1 (6) {
  ["level"]=>
  int(3)
  ["code"]=>
  int(5)
  ["column"]=>
  int(5)
  ["message"]=>
  string(41) "Extra content at the end of the document
"
  ["file"]=>
  string(56) "https://qa.everbridge.net/ws3/services/WebServices3?wsdl"
  ["line"]=>
  int(537)
}
 [2010-08-08 13:25 UTC] nadavvin at gmail dot com
also happen in the newly PHP version 5.3,3
 [2010-08-08 13:28 UTC] nadavvin at gmail dot com
also happen in the newly PHP version 5.3.3
 [2010-09-22 05:36 UTC] tonybrown at cox dot net
I downloaded the latest 5.3.3, running on Fedora 13, ran into this problem, is there a good solution?  I may need to fall back to 5.2.something because we require WSDL. If I can't parse a WSDL file, I'm screwed, because the ICD prescribes it.  I did get non-WSDL to work, but I'm not yet sure if that will be acceptable. I can get the same high level functionality, but then I won't be ICD-compliant. I am also worried that if I fall back to 5.2.something I will then run into other bugs that 5.3.3 might have fixed.
 [2010-10-01 01:35 UTC] pguy at vrcis dot com
Experiencing the same behavior going against a web service hosted on an Oracle 
10g Application Server.
It's using chunked transfer encoding.

my PHP setup:

Downloaded php-5.3.3-nts-Win32-VC9-x86.zip today to my Windows 7 64-bit PC, 
renamed php.ini-development to php.ini, uncommented extension_dir, 
extension=php_soap.dll, and soap.wsdl_cache_dir.
Ran php from the command line using a php file containing the script with the 
SoapClient.

Request headers:

GET /path/endpoint?WSDL HTTP/1.1
Host: oas.internal.local:80
Authorization: Basic dGVzdDp0ZXN0
Connection: close

Response headers:

HTTP/1.1 200 OK
Date: Thu, 30 Sep 2010 22:45:45 GMT
Server: Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server
Cache-Control: private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8

The body is broken into several chunks, all of which appear to have the correct 
sizes.

Interestingly, I tried one of the wsdl urls posted in an earlier comment - 
http://webapi.allegro.pl/uploader.php?wsdl - and it worked fine.  I noticed that 
its body was just one chunk.

As others have noted, the wsdl that 5.3.3 is rejecting works just fine in 5.2.x.

-Peter
 [2011-01-26 17:16 UTC] g at miernicki dot com
It appears this problem is not fixed on 5.3.4 or 5.3.5! I've
instantiated a brand new (out of the box) nuSoap 0.9.5 server, defined
a single service, and still receive the same error on both >>

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing
WSDL:Couldn't load from 'http://server/index.php?wsdl' : Extra content
at the end of the document in /home/user/consume.php:7 Stack trace: 
#0 /home/user/consume.php(7): SoapClient->SoapClient('http://server...')
#1 {main} thrown in /home/user/consume.php on line 7
 [2011-07-12 08:41 UTC] tej dot nri at gmail dot com
I believe that this problem is only happening in php 5.3.* as it was working in php 5.2.*

The solution is also not very difficult.

Steps:
1. Download the WSDL file by $ wget http://example.com/path/to/wsdl/file.xml
2. Put this wsdl file at some location. Let's say the path is /local/path/to/wsdl/file.xml

3. Now create the soap client by the locally saved file like below

------------------------------------------------------------------------------
$soapClient = new SoapClient('/local/path/to/wsdl/file.xml', array('features' => SOAP_USE_XSI_ARRAY_TYPE, 'trace' => 1, 'exceptions' => true));
$result = $soapClient->__soapCall('ServiceName', $data);
------------------------------------------------------------------------------
I believe this will work.
 [2011-09-22 02:47 UTC] kotekp at gmail dot com
seems like:
* php 5.3.5 windows has same bug
* php 5.3.8 linux works fine
 [2011-10-05 07:01 UTC] emuns at quotify dot com
This is happening on PHP 5.3.2 on Ubuntu :(

Confirmed working on 5.2.17
 [2011-11-23 10:02 UTC] dmitry@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2011-11-23 10:49 UTC] dmitry@php.net
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=319714
Log: Fixed bug #48216 (PHP Fatal error: SOAP-ERROR: Parsing WSDL: Extra content at the end of the doc, when server uses chunked transfer encoding with spaces after chunk size)
 [2011-11-23 10:50 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2011-11-23 10:50 UTC] dmitry@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-03 09:50 UTC] scraly at gmail dot com
I have the same issue with linux, php 5.5.3.6-13ubuntu3.6
 [2012-04-18 09:47 UTC] laruence@php.net
Automatic comment on behalf of dmitry
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b3522ffdcb738a2f27b042008351c67dc7965ba8
Log: Fixed bug #48216 (PHP Fatal error: SOAP-ERROR: Parsing WSDL: Extra content at the end of the doc, when server uses chunked transfer encoding with spaces after chunk size)
 [2012-05-16 23:31 UTC] apolinux at gmail dot com
I have the same problem with php 5.3.10-1ubuntu3.1 with Suhosin-Patch released this year.

my ubuntu is pangolin precise.
 [2012-07-23 18:51 UTC] jbl dot foruns at gmail dot com
Same problem here.
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)
Linux srv10 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012 x86_64 
x86_64 x86_64 GNU/Linux
 [2012-07-24 23:38 UTC] rasmus@php.net
Automatic comment on behalf of dmitry
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b3522ffdcb738a2f27b042008351c67dc7965ba8
Log: Fixed bug #48216 (PHP Fatal error: SOAP-ERROR: Parsing WSDL: Extra content at the end of the doc, when server uses chunked transfer encoding with spaces after chunk size)
 [2013-11-17 09:35 UTC] laruence@php.net
Automatic comment on behalf of dmitry
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b3522ffdcb738a2f27b042008351c67dc7965ba8
Log: Fixed bug #48216 (PHP Fatal error: SOAP-ERROR: Parsing WSDL: Extra content at the end of the doc, when server uses chunked transfer encoding with spaces after chunk size)
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 17:01:58 2014 UTC