What is faster for PHP to work with / easier to work with PHP; XML or JSON, and file_get_contents or cURL?

Is there a reason I should choose JSON over XML, or vice versa if they are available? Tips for optimizing performance when working with data channels are also welcome!

+3
source share
4 answers

When it comes to PHP, one of the reasons I choose XML over JSON is that even in PHP 5, the crawl API is not officially supported. You can encode, and you can decode, that's all. There is no verification, there is no effective way to move the key / value pair and the all-in-one, and there is very little support for it. Don't get me wrong, you can just use the foreach loop structure, but it is really cumbersome. JSON was touted as a great data exchange format, as JavaScript easily understood the lexical structure. So when you switch from PHP to JavaScript, it’s great, but when you switch from JavaScript to PHP or PHP to PHP, JSON is not the best choice for data exchange.

+9
source

JSON, , XML . JSON , , , , , .

+5

, , -, . , JSON , , , .

, - . raw, XML.

+2

Regarding the performance of file_get_contents () and cURL, I believe cURL will be a little faster. For your application, you can perform some quick tests to compare the two approaches.

More importantly, I would prefer cURL because file_get_contents () will not work in PHP environments that have a higher level of security (for example, the allow_url_fopen parameter is usually disabled). If your application will only run in your own environment (which you control), file_get_contents () will be fine, but otherwise I would go with cURL for portability.

+1
source

Source: https://habr.com/ru/post/1699066/


All Articles