The other day I purchased a DigitalOcean Managed Database to use as a secondary MySQL server to reduce load on our primary CPanel CentOS server.
This has worked great but every couple of hours our error logs from our PHP scripts fill with the following errors:
[24-Jan-2022 04:16:21 UTC] PHP Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known
[24-Jan-2022 04:16:21 UTC] PHP Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known
[24-Jan-2022 04:16:21 UTC] PHP Warning: mysqli_set_charset(): Couldn't fetch mysqli
[24-Jan-2022 04:16:21 UTC] PHP Warning: mysqli::prepare(): Couldn't fetch mysqli
[24-Jan-2022 04:16:21 UTC] PHP Fatal error: Uncaught Error: Call to a member function bind_param() on null
These errors are originating on this line:
$db = new mysqli("ygo-external-database-do-user-10645539-0.b.db.ondigitalocean.com:25060","username","password", "database");
I don't think it's a firewall issue since it is working most of the time. The website is also using Cloudflare but I don't think that is the issue either as I paused Cloudflare once when it occurred and the issue remained for ~20 minutes or so. Restarting the Litespeed web server tends to fix this immediately but I am non the wiser as to why this is happening.
I'm trying to open a COM port in PHP using the device's library file (file.dll) for the connection.
I get this error:
Fatal error: Uncaught exception 'com_exception' with message 'Source: file.DLL file.DLLDescription: com c:\users\user\folder\com.prg Error in line 9 OLE IDispatch exception code 0 from MSComm: The device is not open.. 1429' in C:\Users\user\folder\index.php:12 Stack trace: #0 C:\Users\user\folder\index.php(12): com->open(1, '115200,n,8,1') #1 {main} thrown in C:\Users\user\folder\index.php on line 12
The file 'com.prg' mentioned in the error does not exist in the folder (hidden files are visible).
I tried reinstalling MSComm, using another cable, using another port, reinstalling device drivers, updating PC drivers.
Here's the code:
<?php
$fp = new COM("file.dll");
echo "<br>". $fp->init();
echo "<br>". $fp->open(1, "115200,n,8,1");
echo "<br>". $fp->close();
?>
In open() command 1 - COM1 port, 115200 - bits per second, n - no parity, 8 - data bits, 1 - stop bits.
The connection works on another computer using the exact same configuration, so the problem here is not the code.
Any ideas?
I installed Mantis BT 1.2.19 on my server and it works well. To benefit from it in my Eclipse-IDE (Mars) I installed the Task-Repo Plugin for Mantis and tried to add the connection.
When I click on "Validate settings" in Eclipse I get the following error:
SOAP-ERROR: Parsing WSDL: Couldn't load from '/var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.wsdl' : failed to load external entity "/var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.wsdl"
In my error-log on the server are the following entries
[14-Oct-2015 11:25:05 Europe/Berlin] [mantisconnect.php] Error Type: SYSTEM WARNING,
Error Description: SoapServer::SoapServer(): I/O warning : failed to load external entity "/var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.wsdl"
Stack Trace:
mantisconnect.php L121 SoapServer(<string>'mantisconnect.wsdl', <Array> { ['features'] => 5 })
[14-Oct-2015 11:25:05 Europe/Berlin] PHP Warning: Uncaught SoapFault exception: [Server] Error Type: SYSTEM WARNING,
Error Description: SoapServer::SoapServer(): I/O warning : failed to load external entity "/var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.wsdl" in /var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mc_api.php:107
Stack trace:
#0 /var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mc_api.php(530): SoapActions::sendSoapFault('Server', 'Error Type: SYS...')
#1 [internal function]: mc_error_handler(2, 'SoapServer::Soa...', '/var/www/vhosts...', 121, Array)
#2 /var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.php(121): SoapServer->SoapServer('mantisconnect.w...', Array)
#3 {main}
thrown in /var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mc_api.php on line 107
[14-Oct-2015 11:25:05 Europe/Berlin] PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from '/var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.wsdl' : failed to load external entity "/var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.wsdl"
in /var/www/vhosts/{myhost}/httpdocs/mantis/api/soap/mantisconnect.php on line 121
The errors above are produced by the Mantis plugin on accessing the URL
188.109.171.76 - - [14/Oct/2015:11:25:05 +0200] "POST /mantis/api/soap/mantisconnect.php HTTP/1.0" 500 1067 "-" "Mylyn/3.17.0 Mylyn-Mantis Connector/3.10.1 Apache Axis/1.4 Eclipse (org.eclipse.epp.package.jee.product) HttpClient/3.1 Java/1.8.0_60 (Oracle) Windows 7/6.1 (amd64; de_DE)"
But even a "normal" GET-access to the URL mentioned above produces the same error
https://{myhost}/mantis/api/soap/mantisconnect.php
No error is produced on accessing
https://{myhost}/mantis/api/soap/mantisconnect.php?wsdl
To solve the problem on my own I checked several ideas:
The file IS existant ... {myhost} is just a placeholder here obviously - placed by me
I switched to the context of the webserver www-data and tried accessing the file ... it IS accessible
So I´ve no idea...
PHP version is 5.5.9-1ubuntu4.13 on Ubuntu 14.04.3 LTS
€dit:
Tracked down the error to the following PHP-line in mantis/api/soap/mantisconnect.php
$server = new SoapServer("mantisconnect.wsdl",
array('features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS)
);
I don´t understand why there an error is thrown - because as I said: it exists and is readable by the webserver...
€edit2:
I replaced the line
$server = new SoapServer("mantisconnect.wsdl",
with
$server = new SoapServer("http://{myhost}/mantis/api/soap/mantisconnect.wsdl",
THIS works... so I´ve a "solution" but I don´t know why the access via file does not work
I Think I found the answere on my own (my workaround failed some hours later - with same error again).
Seems to be a bug in PHP (on Ubuntu) as mentioned here
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1160336
Unresolved since 2013
:-(
My current workaround is disabling soap.wsdl_cache_enabled in php.ini which seems to help for the moment.
I've run into some trouble with a batch newsletter sending background script written in php.
I've noticed lots of differences between running a php via the browser, and via the php executable. I assume this is because php scripts executed directly by the executable don't have any interaction with apache.
For instance, I have to set DOCUMENT_ROOT as an environment variable before calling the script or parse it as an argument, because $_SERVER["DOCUMENT_ROOT"] is not defined.
Now I've run into this problem when I try and connect to my database via PDO. Here's what happens:
C:/Users/hedge/Dev/PHPStorm/gpstudios/www/files/processes/send_newsletters.php hfBH6rCA 2>&1
log.js:137 Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php on line 42
Call Stack:
0.0003 126144 1. {main}() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php:0
0.0016 155392 2. getConnection() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php:14
0.0023 196416 3. Connection->__construct() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\inc\config.php:20
0.0023 196760 4. PDO->__construct() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php:42
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. ' in C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php on line 42
PDOException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php on line 42
Call Stack:
0.0003 126144 1. {main}() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php:0
0.0016 155392 2. getConnection() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php:14
0.0023 196416 3. Connection->__construct() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\inc\config.php:20
0.0023 196760 4. PDO->__construct() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php:42
PHP Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php on line 42
PHP Stack trace:
PHP 1. {main}() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php:0
PHP 2. getConnection() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php:14
PHP 3. Connection->__construct() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\inc\config.php:20
PHP 4. PDO->__construct() C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php:42
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. ' in C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php:42
Stack trace:
#0 C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php(42): PDO->__construct('mysql:host=loca...', '<redacted>', '<redacted>')
#1 C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\inc\config.php(20): Connection->__construct('localhost', '<redacted>', '<redacted>', '<redacted>')
#2 C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php(14): getConnection()
#3 {main}
thrown in C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\class\Connection.php on line 42
It seems localhost can't be resolved, but it doesn't explicitly report that in the logs.
How do I fix this?
If I replace 'localhost' in my PDO constructor with '127.0.0.1', it works. Clearly the issue is with resolving localhost.
I am using proc_open() to start the script. I found that if I run the script through CMD prompt, it works.
it looks like this: start /B php C:\Users\hedge\Dev\PHPStorm\gpstudios\www\files\processes\send_newsletters.php
The issue would appear to be with proc_open then...
EDIT
The problem is still unresolved but I've worked out the root of it:
proc_open($cmd, [['pipe', 'r'],['pipe', 'w'],['pipe', 'w']], $pipes, NULL, $environment_variables);
The problem is $environment_variables, an associative array which contains - you guessed it - environment variables.
I came across this on php.net: http://php.net/manual/en/function.proc-open.php#117912
For those who are finding that using the $cwd and $env options cause proc_open to fail (windows). You will need to pass all other server environment variables;
However, even when I do just that, it still fails to resolve localhost.
EDIT 2
Problem resolved. The code provided by the helpful user on php.net used array($_SERVER), when in fact, you just need $_SERVER.
So the code now looks like:
proc_open($cmd, [['pipe', 'r'],['pipe', 'w'],['pipe', 'w']], $pipes, NULL, array_merge($_SERVER, $environment_variables))
Huzzah! Thanks for the help everybody.
Solutuion found here: http://php.net/manual/en/function.proc-open.php#117912
For those who are finding that using the $cwd and $env options cause
proc_open to fail (windows). You will need to pass all other server
environment variables;
The helpful user got it slightly wrong though, they put $_SERVER in an array. This is what worked for me:
proc_open($cmd, [['pipe', 'r'],['pipe', 'w'],['pipe', 'w']], $pipes, NULL, array_merge($_SERVER, $environment_variables))
IMHO, your host not found, please check host or see this
PHP php_network_getaddresses: getaddrinfo failed: No such host is known
mysql_connect: php_network_getaddresses: getaddrinfo failed: No such host is known using file values
so my script is running in my localhost(pc1) and i am trying to save an excel file using phpexcel in a network folder (\\pc2\c$\myfolder) but it gives me an error saying that i dont have permission in that particular folder eventhough i have a full access. I can manually create, edit or deleta a file in that folder.
error msg:
Warning: fopen(\\pc2\c$\myfolder\12122014.xls) [function.fopen]: failed to open stream: Permission denied in C:\wamp\www\receivables\PHPExcel\Shared\OLE\PPS\Root.php on line 90
Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Can't open \\pc2\c$\myfolder\12122014.xls. It may be in use or protected.' in C:\wamp\www\receivables\PHPExcel\Shared\OLE\PPS\Root.php:93 Stack trace: #0 C:\wamp\www\receivables\PHPExcel\Writer\Excel5.php(226): PHPExcel_Shared_OLE_PPS_Root->save('\\ipcsvs001\c...') #1 C:\wamp\www\receivables\index.php(241): PHPExcel_Writer_Excel5->save('\\ipcsvs001\c...') #2 {main} thrown in C:\wamp\www\receivables\PHPExcel\Shared\OLE\PPS\Root.php on line 93
note: i am using wamp server(not sure if this matters)