libxml_use_internal_errors(true) doesn't remove all warnings - php

I want to GET a XML feed using simplexml_load_file() and I want to handle the errors by myself. The problem is, libxml_use_internal_errors(true) does not remove all the warnings. Here is my exact code:
<?php
libxml_use_internal_errors(true);
$url = "http://feeds.feedburner.com/GoogleOnlineSecurityBlog";
$res = simplexml_load_file($url);
When I purposefully write a typo in the URL, I get these warnings:
Warning: simplexml_load_file(): php_network_getaddresses: getaddrinfo failed: Unknown host. in C:\xampp\htdocs\test.php on line 4
Warning: simplexml_load_file(http://feeds.feedburener.com/GoogleOnlineSecurityBlog): failed to open stream: php_network_getaddresses: getaddrinfo failed: Unknown host. in C:\xampp\htdocs\test.php on line 4
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://feeds.feedburener.com/GoogleOnlineSecurityBlog" in C:\xampp\htdocs\test.php on line 4 error
Adding or removing libxml_use_internal_errors(true) only adds/removes the last warning and not the first 2. What did I do wrong? I have PHP 7.2.2.
Thank you for your help.

Related

Simple HTML DOM Parser error: "Warning: file_get_contents()"

I was just starting to test use Simple HTML DOM Parser to parse google.com, while getting the following error:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /Applications/Ampps/www/scraper/simplehtmldom_1_9_1/simple_html_dom.php on line 82
Warning: file_get_contents(): Failed to enable crypto in /Applications/Ampps/www/scraper/simplehtmldom_1_9_1/simple_html_dom.php on line 82
Warning: file_get_contents(https://google.com): failed to open stream: operation failed in /Applications/Ampps/www/scraper/simplehtmldom_1_9_1/simple_html_dom.php on line 82
And my scraper_test.php looks like this:
include('./simplehtmldom_1_9_1/simple_html_dom.php');
$html = file_get_html('https://google.com');
echo $html->find('title', 0)->plaintext;

Error fetching data from youtube in xml format

I am trying to fetch youtube videos using Youtube Data API URL. Whenever i paste the URL directly in the address bar, it perfectly shows the result. But whenever i try to use that URL in simplexml_load_file() function, i get errors. I cannot figure out what is going on.
This is how i am doing this.
$url = "https://gdata.youtube.com/feeds/api/videos/-/cat";
$output = simplexml_load_file($url);
echo "<pre>";
print_r($output);
echo "</pre>";
I am getting this error message.
Warning: simplexml_load_file(): SSL: The operation completed successfully. in J:\xampp\htdocs\youtube\tube.php on line 23
Notice: simplexml_load_file(): send of 38 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in J:\xampp\htdocs\youtube\tube.php on line 23
Notice: simplexml_load_file(): send of 25 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in J:\xampp\htdocs\youtube\tube.php on line 23
Notice: simplexml_load_file(): send of 2 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in J:\xampp\htdocs\youtube\tube.php on line 23
Warning: simplexml_load_file(https://gdata.youtube.com/feeds/api/videos/-/cat): failed to open stream: HTTP request failed! in J:\xampp\htdocs\youtube\tube.php on line 23
Warning: simplexml_load_file(): I/O warning : failed to load external entity "https://gdata.youtube.com/feeds/api/videos/-/cat" in J:\xampp\htdocs\youtube\tube.php on line 23
I tried to use file_get_contents() function it also gives error.
$url = "https://gdata.youtube.com/feeds/api/videos/-/cat";
$output = file_get_contents($url);
echo $output;
I get these errors using above code.
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known. in J:\xampp\htdocs\youtube\tube.php on line 15
Warning: file_get_contents(https://gdata.youtube.com/feeds/api/videos/-/cat): failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in J:\xampp\htdocs\youtube\tube.php on line 15
I also tried to use simplexml_load_string() function it also gives error.
$url = "https://gdata.youtube.com/feeds/api/videos/-/cat";
$output = simplexml_load_string($url);
echo "<pre>";
print_r($output);
echo "</pre>";
The above code gives me these errors.
Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in J:\xampp\htdocs\youtube\tube.php on line 14
Warning: simplexml_load_string(): https://gdata.youtube.com/feeds/api/videos/-/cat in J:\xampp\htdocs\youtube\tube.php on line 14
Warning: simplexml_load_string(): ^ in J:\xampp\htdocs\youtube\tube.php on line 14
I am using XAMPP v3.2.1 to run my script.
Please help. Thanks.
First you have to check that remote file access is enabled, read the PHP manual page about Using remote files.
After that, and if your firewall is not blocking connections, almost any option that you tried should work. But, in any case, here you have one using simpler commands, or at least simpler concerning what is working internally. Just a good old fopen.
// initialize variables
$url = 'https://gdata.youtube.com/feeds/api/videos/-/cat';
$content = false;
$handle = false;
// open the url/file
$handle = fopen( $url, 'r' );
// get the content from streaming
$content = stream_get_contents($handle);
// close the file reading session
fclose( $handle );
var_dump( $content );

Severity: Warning failed to open stream: Permission denied Filename: core/Loader.php

I have the following error :
A PHP Error was encountered
Severity: Warning
Message: include(/Applications/XAMPP/xamppfiles/htdocs/caretech/application/views/request_form.php) [function.include]: failed to open stream: Permission denied
Filename: core/Loader.php
Line Number: 833
A PHP Error was encountered
Severity: Warning
Message: include() [function.include]: Failed opening 'application/views/request_form.php' for inclusion (include_path='.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear')
Filename: core/Loader.php
Line Number: 833
When I run the following script : http://domainname.com/caretech/transactions/view_request on my browser. What could be the cause of the above error? How can I solve the problem?
It seems like the user your web server (actually PHP, but in you case that is run by Apache in the form of an extension) is running as does not have permissions to open the file in question. Check the permissions and change them accordingly and you should most likley be good to go.

PHP warning include() related

Recently I opened my error_log files and noticed that it have several include() related error message. Website have about 1500 daily visitor but this message shows only about 3 times in month for example I may have group of 10 error on 06 Feb then group of 15 error on 20 Feb etc.
Here's example of error text:
[05-Jun-2013 15:57:39] PHP Warning: include() [function.include]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/user33/public_html/example/file3.php on line 6
[05-Jun-2013 15:57:39] PHP Warning: include(http :// www . example . com/file.php) [function.include]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/user33/public_html/example/file3.php on line 6
or
[19-Jul-2013 17:42:17] PHP Warning: include() [function.include]: Failed opening 'http:// www. example. com/ file.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/user33/public_html/example/file4.php on line 5
[19-Jul-2013 17:42:17] PHP Warning: include(http: // www. example. com/file.php) [function.include]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
in /home/user33/public_html/example/file5.php on line 11
P.S. Website don't use any CMS and have simple page that contains mostly HTML code with several PHP includes.
P.S. 2. Does using absolute path in include() may lead to this errors? e.g. I use include("http://www.example.com/file.php") instead of include("../file.php").
What that may be?
Yes, you have an issue because you are using include("http://www.example.com/file.php") instead of include("../file.php") see include docs for more details

PHP file_get_contents not working

i am having a problem with PHP file_get_contents.
$html = file_get_html($csfd_link);
Writes an error:
Warning: file_get_contents() [function.file-get-contents]:
php_network_getaddresses: getaddrinfo failed: Name or service not
known in /home/vo003500/www_root/admin/simple_html_dom.php on line 76
Warning: file_get_contents(http://www.example.com/)
[function.file-get-contents]: failed to open stream:
php_network_getaddresses: getaddrinfo failed: Name or service not
known in /home/vo003500/www_root/admin/simple_html_dom.php on line 76
I do not know what it is. The server is allow_url_fopen ON
Thanks
Edit:
Until now it worked, but the last 2 weeks not working...
It looks like your suffering from DNS (Domain Name Service) resolution error. Make sure there is a proper DNS server entry in /etc/resolv.conf.

Categories