I need my website to be able to use fopen() to access files on my file streaming server, which our admin has configured to use port 8000. But it errors out and I believe it's because of the port number. I have allow_url_fopen enabled in php.ini too, so I don't think that's the issue.
Warning: fopen(http://129.237.213.244:8000/mp3/First_8864.mp3) [function.fopen]:
failed to open stream: Connection refused in _npp_get_mp3() (line 23 of
/home2/ab83417/public_html/drupal/sites/all/modules/npr_player_pack/npp_library.php).
So my question is: Can I somehow tell the webserver or our stream server (icecast, btw) to stop being so picky, or should I use some other php function like curl?
You should make sure that you have allow_url_fopen set to 1.
Launch the following script:
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
echo ini_get('allow_url_fopen')."<br />";
$x = file_get_contents('http://129.237.213.244:8000/mp3/First_8864.mp3');
$y = fopen('http://129.237.213.244:8000/mp3/First_8864.mp3',"rb");
It gives me simple 1 and no warnings. If you also get 1 but have warnings you should run the script in other browser and change your ip earlier (for example vpn). It's possible that this site has banned your ip so you cannot connect with this site/url.
For the past four hours I have been trying to configure TCAdmin to work with whmcs. I set up the server in the server setting of WHMCS and added all the configurable options. I got my first demo order and when I select "Accept Order" I get this error:
Order Accept Encountered Problems
Curl error: couldn't connect to host Url: http://xx.xx.xxx.xxx:8880/billingapi.aspx
For some reason WHMCS can't connect, but when I connect I get this: "Visit http://help.tcadmin.com for help". I tried that. Still no luck.
So I went into my server, found the billingapi.aspx file and it said this:
This is a marker file generated by the precompilation tool, and should not be deleted!"
Does anyone have any suggestions or solutions? All help is appreciated :)
-Max
Curl is failing to connect but you think it should be able to? There are a few things to check:
Is the address being passed to Curl really right? (It's so easy to get this wrong!)
Is the target host reachable from the host making the request (the origin)? Firewall rules can cause all sorts of strange problems here. Check if you can do a read-only request from the origin and get through that way.
Is the target port on the target host accessible from the origin? Again, it's the firewall, and port 8880 is not one that I'd expect to normally be a permitted outgoing target in an aggressive firewall regime; a specific rule may well be needed.
Is there a problem with DNS? Hopefully not, but if name resolution itself keeps failing then that might be a significant issue. (This won't be the case if you use an IP address instead of a DNS host name, but that can cause the request to fail in other ways — such as if the target hosts many sites — so don't jump to conclusions here.)
Other problems that are theoretically possible (e.g., bad request contents, wrong path in the URL) would give different error messages.
i am completely new to php from python. in python, i am fairly familiar with getting json results from webpages. however whatever i seem to do in php is not working. the code i am using is.
<?php
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=hello&safe=off";
$data = json_decode(file_get_contents($url));
echo $data;
?>`
yet this does absolutely nothing. is there anything wrong with what i am doing? also i ran it through ideone.com and got these errors.
`PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/VQMKwy/prog.php on line 3
PHP Warning:file_get_contents(http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=hello&safe=off): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/VQMKwy/prog.php on line 3`
As soon as you'll solve the problem posted above (which seems related to your server configuration, as file_get_contents works fine for me) you'll encounter another error.
json_decode will return an object of class stdClass. You can't just echo that out.
The fastest way to echo an array is to use
var_dump($data);
apart from that, the code runs fine on my local machine. I've just replaced echo with var_dump
The hint posted by Rob should solve the problem but if it doesn't and if you're running on Apache try to run this command:
sudo rc.d stop httpd; sudo rc.d start httpd
this will force Apache to stop and start thus updating /etc/resolv.conf
I am having DNS issues with a certain target domain. I am using fopen() (but same issue with other functions) to retreive an image, but I get this error:
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: No such host is known
I am able to ping or nslookup the domain from the command prompt, but for some reason php throws this error. When I try fopen('http://www.google.com', r); or other domains, all goes fine. But above mentioned domain simply won't resolve with PHP. I have flushed the DNS, restarted Apache, but still no luck..
I have tried with:
Windows 7, Apache 2.2 PHP 5.3.6
Windows server 2008r2, Apache 2.2 PHP 5.3.6
What can cause this single domain to not resolve?
IMO it's the different way to resolve a name from the OS and PHP.
Try:
echo gethostbyname("host.name.tld");
and
var_export (dns_get_record ( "host.name.tld") );
or
$dns=array("8.8.8.8","8.8.4.4");
var_export (dns_get_record ( "host.name.tld" , DNS_ALL , $dns ));
You should found some DNS/resolver error.
Your "localhost" cannot resolve the name www.google.com, which means your machine doesn't/can't reach a valid dns server.
Try ping google.com on the console of that machine to verify this.
It is more flexible to use curl instead of fopen and file_get_content for opening a webpage.
getaddrinfo failed: No such host is known
The above error is caused due to mistake in Database Host (DB_HOST) in .env file
Open the .env file and Specially check for this env variables
DB_HOST=localhost
DB_DATABASE=database_name
DB_USERNAME=database_username
DB_PASSWORD=database_password
Your target domain might refuse to send you information. This can work as a filter based on browser agent or any other header information. This is a defense against bots, crawlers or any unwanted applications.
I had a lot of issues with this on Windows. I just performed git clone, copied my .env.example file to .env. updated it, and executed my trusty PHP script to update initial database used for a project. And it failed, and whatever I did, it kept on failing. Out of desperation, I reinstalled MySQL, but that didn't fix things.
Finally, I figured it out. PHP script extracted the settings from .env file using file_get_contents(), and exploding it using \n, but the .env file was encoded with CRLF, so my DB_HOST was empty. After I changed the encoding of the .env file, everything was fine.
So, my point is, echo the parameters supplied to mysqli::construct, and it might be the culprit.
A weird thing I found was that the environment variable SYSTEMROOT must be set otherwise getaddrinfo() will fail on Windows 10.
What had caused this error on my side was the following line
include_once dirname(__FILE__) . './Config.php';
I managed to realize it was the culprit when i added the lines:
//error_reporting(E_ALL | E_DEPRECATED | E_STRICT);
//ini_set('display_errors', 1);
to all my php files.
To solve the path issue i canged the offending line to:
include_once dirname(__FILE__) . '/Config.php';
When my script parses an RSS feed from my local Apache server, it parses fine but when I upload script to the remote hosting server it gives the error:
Warning: Magpie RSS: Failed to fetch (url) and cache is off in magpierss-0.6/rss_fetch.inc
on line 231.
I have searched for possible answers and any suggestions are around enabling and changing cache lifetime. I think that is not the problem - it looks like the problem is with remote hosting Apache server or denied access to my host.
Can anyone help?
check that magpie can open the rss url. Usually with curl being enabled or allow_url_fopen on your server. Also make sure that magpie is able/allowed/permitted to create caching files (if any)
This could be caused by a bad url, the server is busy or not having remote file access allowed in your host.
$errormsg = "Failed to fetch $url "; in source indicative of problem getting to host.
Try checking access from the remote host - if you have ssh & curl enabled just do
curl (url)