class restRendering
{
public $RestUrl='http://www.myweather2.com/developer/forecast.ashx?uac=AnwWoM6K2.&output=xml&query=10591';
public $XSLTPath="receipe.xsl";
//setter method for test url
public function setRestUrl( $value )
{
$this->RestUrl = $value;
}
public function setXSLTPath( $value )
{
$this->XSLTPath = $value;
}
//It renders the iframe with base url and path.
public function render(){
//load the XML
$xml_Doc = new DOMDocument();
if($xml_Doc->load($this->RestUrl))
{
//load the XSL
$xsl= new DOMDocument();
$xsl->load($this->XSLTPath) or die("can not load XSLT file");
$xslt = new XSLTProcessor($xsl);
$xslt->importStyleSheet($xsl);
print $xslt->transformToXML( $xml_Doc ) or die("Trasform Error");
}
else{
echo "Can not load the url";
}
} //End of Render method.
}
While executing I am getting this error:
Warning: DOMDocument::load(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\xampp\htdocs\sweet\restRendering.php on line 25
Warning: DOMDocument::load(http://www.myweather2.com/developer/forecast.ashx?uac=AnwWoM6K2.&output=xml&query=10591): failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\xampp\htdocs\sweet\restRendering.php on line 25
Warning: DOMDocument::load(): I/O warning : failed to load external entity "http://www.myweather2.com/developer/forecast.ashx?uac=AnwWoM6K2.&output=xml&query=10591" in D:\xampp\htdocs\sweet\restRendering.php on line 25
According to this error:
Warning: DOMDocument::load(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\xampp\htdocs\sweet\restRendering.php on line 25
your server has a problem with DNS. It can't connect to www.myweather2.com because it can't translate it to an IP address.
Try
nslookup www.myweather2.com
and see what the results are. When you solve that problem, your script will probably work.
Related
I'm trying to connect to a soap service using a WSDL file in php 5.6
The snippet below works fine if I'm on the network, but if I'm disconnected I get a fatal error.
try {
$soap_client = new SoapClient($wsdl_file, ['exceptions' => true]);
}
catch (SoapFault $fault) {
echo 'poop';
}
catch (Exception $exception) {
echo 'pee';
}
edit: it does seem to do something with the SoapFault, because I can see my 'poop' debug message, but it still results in a fatal error
These are the errors I get
Warning (2): SoapClient(): php_network_get_addresses: getaddrinfo failed: No such host is known.
Warning (2): SoapClient(http://soap.service.com/serivce.svc) [soapclient.soapclient]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known.
Error: SOAP-ERROR: Parsing Schema: can't import schema from 'http://soap.service.com/serivce.svc'
How can I gracefully handle the error so that php continues to run, so I can set a variable and render an HTML page indicating that there was a problem connecting
This was a cakephp issue
https://github.com/cakephp/cakephp/issues/8501
$restore = error_reporting(0);
try {
$soap_client = new SoapClient($wsdl_file, ['exceptions' => true]);
}
catch (SoapFault $e) {
trigger_error($e->getMessage()); // Overwrites E_ERROR with E_USER_NOTICE
}
finally {
error_reporting($restore);
}
I have the following , relatively simple connection script to a database :
The below script is just creating a generic interface :
<?php
//Filename: IConnectInfo.php
interface IConnectInfo
{
const HOST ="localhost";
const UNAME ="root";
const PW ="";
const DBNAME = "login";
public static function doConnect();
}
?>
The script below, that makes use of the above interface:
<?php
//FILENAME :: UniversalConnect.php
ini_set("display_errors","1");
ERROR_REPORTING( E_ALL | E_STRICT );
include_once('IConnectInfo.php');
class UniversalConnect implements IConnectInfo
{
private static $server=IConnectInfo::HOST;
private static $currentDB= IConnectInfo::DBNAME;
private static $user= IConnectInfo::UNAME;
private static $pass= IConnectInfo::PW;
private static $hookup;
public static function doConnect()
{
self::$hookup=mysqli_connect(self::$server, self::$user, self::$pass, self::$currentDB);
if(self::$hookup)
{
echo "Successful connection to MySQL:<br/>";
}
elseif (mysqli_connect_error(self::$hookup))
{
echo('Here is why it failed: ' . mysqli_connect_error());
}
return self::$hookup;
}
}
?>
Now till here everything is neat and clean and works fine :
I tested the above two files are working , by adding the following 2 lines at the end of the above file .
$instance = new UniversalConnect();
$instance::doConnect();
I get a message "Successful connection to MySQL:" , perfect !!!
now comes the 3rd file : (I have commented out some of the code to make things simple) :
<?php
//FILENAME DataEntry.php
require_once('tablework/UniversalConnect.php');
class DataEntry
{
//Variable for MySql connection
private $hookup;
private $sql;
private $tableMaster;
//Field Variables
private $name;
private $email;
private $lang;
public function __construct()
{
//Get table name and make connection
$this->tableMaster="basics";
if($this->hookup=UniversalConnect::doConnect()){
echo "<b>connected</b>";
}else{
echo "<b>Not connected</b>";
}
}
}
$instance = new DataEntry();
?>
Now when i run the above file , somehow the connection to the database fails ! even though in UniversalConnect.php the connection is successful !
The error i get is
Here is why it failed: php_network_getaddresses: getaddrinfo failed:
No such host is known. Not connected.
I really don't understand why when the connection is made in UniversalConnect.php and the same connection is being returned to dataEntry.php , does the connection Fail ! .
EDIT :: List of errors :
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo
failed: No such host is known. in
C:\xampp\htdocs\Login2.0\tablework\UniversalConnect.php on line 19
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses:
getaddrinfo failed: No such host is known. in
C:\xampp\htdocs\Login2.0\tablework\UniversalConnect.php on line 19
Here is why it failed: php_network_getaddresses: getaddrinfo failed:
No such host is known. Warning: mysqli_connect():
php_network_getaddresses: getaddrinfo failed: No such host is known.
in C:\xampp\htdocs\Login2.0\tablework\UniversalConnect.php on line 19
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses:
getaddrinfo failed: No such host is known. in
C:\xampp\htdocs\Login2.0\tablework\UniversalConnect.php on line 19
Here is why it failed: php_network_getaddresses: getaddrinfo failed:
No such host is known. Not connected.
I would appreciate any help .
Thank you .
Tenali .
So I have taken a example from php.net to see php ssh2 workings
so the code is
<?php
$connection = ssh2_connect('shell.example.com', 22);
if (ssh2_auth_password($connection, 'username', 'secret')) {
echo "Authentication Successful!\n";
} else {
die('Authentication Failed...');
}
?>
When I am putting wrong information it is giving me some error instead of telling me Authentication Failed.
The Error is
Warning: ssh2_connect(): php_network_getaddresses: getaddrinfo failed: Name not known in
/var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/ssh2.php on line 2 Warning: ssh2_connect(): Unable to connect to
shell.example.com on port 22 in /var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/login/ssh2.php on
line 2 Warning: ssh2_connect(): Unable to connect to shell.example.com in
/var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/login/ssh2.php on line 2 Warning:
ssh2_auth_password() expects parameter 1 to be resource, boolean given in /var/zpanel/hostdata/zadmin/public_html/whothehellcareswhatisthis/login/ssh2.php
on line 4 Authentication Failed...
But when I am putting correct information it is not giving any error.
The problem is that shell.example.com doesn't actually exist and the call to ssh2_connect() fails to return a resource.
Your code should be checking to see if ssh2_connect() successfully makes a connection and returns a resource before attempting to use the resource with ssh2_auth_password().
$connection = ssh2_connect('some.valid.ssh.host', 22);
if (!$connection) {
throw new Exception("Could not connect to server.");
}
if (!ssh2_auth_password($connection, 'name', 'password')) {
throw new Exception("Authentication failed!");
}
// SSH connection authenticated and ready to be used.
$url=$row1['content_url'];
$file_handle = fopen($url,"r");
$line=fread($file_handle,400);
$line1 = wordwrap($line,400,"</br>" );
fclose($file_handle);
the above give is my code for reading data in the text file...
it is working fine in my localhost...
But it is not working in serevr.....
Warning: fopen() [function.fopen]: php_network_getaddresses:
getaddrinfo failed: Name or service not known in
/home/content/08/11968108/html/dev/index.php on line 57
Warning: fread() expects parameter 1 to be resource, boolean given in
/home/content/08/11968108/html/dev/gopi/index.php on line 58
Warning: fclose() expects parameter 1 to be resource, boolean given in
/home/content/08/11968108/html/dev/gopi/index.php on line 60
Make sure the URL in $url contains a wrapper (like http).
Explanation
fopen("www.domain.com","r");
This will look for a local file named www.domain.com
fopen("http://www.domain.com","r");
This will try to get the external file http://www.domain.com (if allow_url_fopen is enabled)
But your error could also indicate an old cached DNS record. If you can, try to change your name server on the production system (e.g.: 8.8.8.8 for the name server from google).
If you just need to handle the warnings that are thrown (as I did), you may just do this to turn them into Exceptions that can be handled:
set_error_handler(
function ($err_severity, $err_msg, $err_file, $err_line, array $err_context) {
// do not throw an exception if the #-operator is used (suppress)
if (error_reporting() === 0) return false;
throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line );
},
E_WARNING
);
try {
$fp = fopen("http://example.com","r");
} catch (Exception $e) {
echo $e->getMessage();
}
restore_error_handler();
Solution based on this thread/question.
This examples are from lynda php beyond basic
config.php
<?php
defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
defined('DB_USER') ? null : define("DB_USER", "root");
defined('DB_PASS') ? null : define("DB_PASS", "");
defined('DB_NAME') ? null : define("DB_NAME", "photo_gallery");
?>
database.php
<?php
require_once('config.php');
class MySQLDatabase {
private $connection;
function __construct(){
$this->open_connection();
}
public function open_connection(){
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$this->connection) {
die("Database connection failed: " . mysql_error());
} else {
$db_select = mysql_select_db(DB_NAME, $this->connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
}
}
public function close_connection(){
if(isset($this->connection)) {
mysql_close($this->connection);
unset($connection);
}
}
public function query($sql) {
$result = mysql_query($sql, $this->connection);
$this->confirm_query($result);
return $result;
}
private function confirm_query($result){
if (!$result) {
die("Database query failed: " . mysql_error());
}
}
}
$database = new MySQLDatabase();
?>
index.php
<?php
require_once("../includes/database.php");
if (isset($database)) {
echo "true";
} else {
echo "false";
}
?>
Now here my problem when I tried index.php run it on the browser i get an error
error says:
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166
Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13
Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13
Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13
Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13
Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://DB_SERVER:3306) in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13
Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\photo_gallery\includes\database.php on line 13
Database connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known.
I somehow fix the error by renaming config.php
So here's my question why i got this error? is config.php filename the problem?
The video tutorial from Lynda php beyond basics didn't get this error.
There is some sort of error with your local configuration, maybe because you have some third party PEAR installed, hence the error message:
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166
You should revise what packages and libraries your system use, because this error message is a sign of outdated code (Deprecated). Personally, I use XAMPP on Windows with my project also having config.php in its htdocs folder without any sorts of error like these. The problem is that the linked file is for php4. On my system, the 166th line reads as follows:
$this->container = new Config_Container('section', 'root');
config.php is a conventional and general name of calling the configuration file, there is no problem with it. Keeping it with this name lowers no security barriers which could be fixed by merely renaming it.
The other errors will be fixed if your project succeeds in loading the configuration file. Also:
Warning:
Please, don't use mysql_* functions to write new code. They are no longer maintained and the community has begun the deprecation process. See the red box?
Instead, you should learn about prepared statements and use either PDO or MySQLi. This article should give some details about deciding which API to use. For PDO, here is a good tutorial.
It might be due to presence of "config.php" and "Config.php" files in same directory.
In windows,file names are not case sensitive.
In linux, they are.