I use a script that regularly reads three CardDAV directories of family members from the iCloud several times a day and synchronizes the prepared address data with our telephone system. This has worked flawlessly for years. Now access to one of the CardDAV directories is disrupted: in the majority of accesses, the XML string returned by the server is suddenly unreadable:
PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in ...
PHP Warning: simplexml_load_string(): Moved Permanently in ...
PHP Warning: simplexml_load_string(): ^ in ...
Then again it is possible to do it a few times in a row without any problems.
First of all, I changed the command for reading in the code, according to a recommandation here, as follows from
$xml = new \SimpleXMLElement($body, LIBXML_PARSEHUGE);
to
$xml = simplexml_load_string($body,'SimpleXMLElement', LIBXML_PARSEHUGE);
This has also only led to sporadic success. Then I subjected all vCards to an intensive inspection and tried to eliminate supposedly illegible characters. This even went so far that all saved contacts were deleted from the iCloud account and read back from a *.VCF file only after checking. Same result: somtimes it works - often not!
Then I examined the body of the request in the code and found that in the event of an error, instead of XML data, only the string "Permanently Moved" was found there (like in the error message above).
I then changed the server address slightly, as experience has shown that access is still possible. Here, too, the error of an empty response could not be reproduced: sometimes access works, then often not.
As a reminder: Contacts from other iCloud accounts can still be read out 100% error-free.
I am totally at my wits end :(