SSL Broken Pipe with PHP - php

My error output looks like this:
PHP Warning: fwrite(): SSL: Broken pipe in /home/whitelot/public_html/webservies/mylastwishnew/apnstest.php on line 89
and then every subsequent write to that resource gets the error:
PHP Warning: fwrite(): SSL: Broken pipe in /home/whitelot/public_html/webservies/mylastwishnew/apnstest.php on line 89
It works for a while, for maybe a few hundred messages/payloads, then all of a sudden pipe breaks and water goes all over the floor.
Anyone have any ideas if there is a good fix for this problem?

I found that using the
'keep_alive' => false
option for
new SoapClient($url, $options);
solved the issue in my case. It seems like if you don't use keep_alive = false, the SOAP connection tries to re-use a previous connection, which gets rejected by SSL. See https://bugs.php.net/bug.php?id=60329
Also, make sure this is not a question of max_execution_time or another limit that might prevent the SSL connection to finish successfully.

Related

How to prevent fwrite(): Connection reset by peer

I have cron which is using fwrite function and after cron is running 1 hour it will crash with error:
fwrite(): send of 29 bytes failed with errno=104 Connection reset by
peer
on line:
$fw = #fwrite($this->sock, $msg."\r\n");
After this I always close connection by
fclose($this->sock);
It seems that it is something wrong inside PHP core and DNS resolver because after that I have some problems resolve hostnames to ip adrress. In my functionality is also used getmxrr() and gethostbyname() functions.
How to prevent this problems?
I got answer from PHP community like this:
Inside fwrite is part code of streaming and sometimes it could happen. They said that it is impossible to fix it on fwrite because it can change some functionality of other functions which using streaming too.
Soo in finaly its property not fault.
After some experiments i used more working solution.
I replaced fsockopen function with socket_create and socket_connect and its much much better. Function fsockopen sometimes not conneted correctly.

PHP ftp_get causing warning and not downloading file

I've got a fairly simple cron job that pulls down some files from an FTP server - none of the files are particularly large, but I'm constantly getting the following:
Connected to voip.colefabrics.com, for user colefabrics\absolute
Warning: ftp_get(): Opening BINARY mode data connection. in /home/www/colefabrics.com/httpdocs/libs/classes/class.ftpObj.php on line 56
There was a problem while downloading website/items.csv
Attempt 2:
Connected to voip.colefabrics.com, for user colefabrics\absolute
Warning: ftp_get(): Opening BINARY mode data connection. in /home/www/colefabrics.com/httpdocs/libs/classes/class.ftpObj.php on line 56
There was a problem while downloading website/items.csv
...snip...
I've been through all the other posts relating to this, tried to enforce passive mode, increased the timeout, but nothing is working.
Does anyone know what might be causing this, and what I can do to try and resolve it?
To confirm, it's working fine via a 'normal' FTP client, it's only via PHP that I have a problem.

PHP (5.5.7) Warning connecting to MySQLi in Windows Servers 2008 R2

I'm running Moodle on PHP 5.5.7 64bit nts on Windows Server 2008 R2 with MySQL 5.5.36.
Up until two days ago, there were no problems. To deal with Xdebugger being such a memory hog, an extra CPU and more memory was assigned to the virtual machine. The Windows license was also activated. The entire vm was rebooted. (I had restarted the machine before prior to this, with no problems).
I am now receiving the following warning when I access any page on the site:
PHP Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
in C:\inetpub\wwwroot\moodle\lib\dml\mysqli_native_moodle_database.php on line 375
I created a test php page that simply consists of the following:
$mysqli = new mysqli("127.0.0.1", "moodleuser", 'xxxx', "moodle", 3306);
if ($result = $mysqli->query("SELECT * from mdl_user limit 10")) {
echo "Select returned $result->num_rows";
} else {
echo "Error";
}
$mysqli->close();
I receive the following output:
PHP Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.in C:\inetpub\wwwroot\moodle\info.php on line 17
PHP Warning: mysqli::query(): Couldn't fetch mysqli in C:\inetpub\wwwroot\moodle\info.php on line 18
PHP Warning: mysqli::close(): Couldn't fetch mysqli in C:\inetpub\wwwroot\moodle\info.php on line 24
I have checked that "127.0.0.1 localhost" exists in my hosts file and that the IPv6 "::1" line has been commented out.
I have also attempted to use "localhost" but same problem.
The bizarre thing is that if I refresh the page, occasionally, and completely at random, the warning doesn't occur and the correct output is given.
I have attempted to disable the warnings, but php appears to be ignoring me. Also, disabling the warning is not exactly ideal.
Any ideas?
EDIT:
So after much pain staking back and forths between PHP and MySQL and IIS, it looks like (once again) it was php.ini to blame.
To be honest, I cant even tell you which setting was the problem - but I changed all possible timeout related settings in php.ini to a large number (10000 or -1 depending on the setting), as well as the connection_timeout for mysql in my.ini.
I am still yet to figure out which one was causing the problem, but will edit this post if I ever do.
So after much pain staking back and forths between PHP and MySQL and IIS, it looks like (once again) it was php.ini to blame.
To be honest, I cant even tell you which setting was the problem - but I changed all possible timeout related settings in php.ini to a large number (10000 or -1 depending on the setting), as well as the connection_timeout for mysql in my.ini.
I am still yet to figure out which one was causing the problem, but will edit this post if I ever do.

More than max_user_connections in CodeIgniter app?

I'm getting what looks like rather serious database errors in my CodeIgniter application. In the log file it says:
User anders already has more than 'max_user_connections' active connections
And there are several hundred of those lines... I've read a bit by Googling, and some suggested that it was because you didn't close the connection after it was used, but others said that this was nonsense, and that the connection was automatically closed (which is what I read in the docs too).
Also, later in the log file, I have these error messages:
ERROR - 2011-10-12 10:50:19 --> Severity: Warning --> file_get_contents(http://localhost/expertinfo/error/error_general) [function.file-get-contents]: failed to open stream: HTTP request failed! /Applications/MAMP/htdocs/expertinfo/application/errors/error_general.php 4
This seems to have something to do with the fact that I'm using a custom error page by using
echo file_get_contents($config['base_url'] . 'error/error_db');
to redirect to a custom page.
Finally, I'm also getting:
ERROR - 2011-10-12 10:52:19 --> Severity: Warning --> mysql_pconnect() [function.mysql-pconnect]: Can't connect to MySQL server on 'mydb24.surftown.se' (4) /Applications/MAMP/htdocs/expertinfo/system/database/drivers/mysql/mysql_driver.php 88
In these last two, I don't understand what the local path is doing there (The path to my CodeIgniter app on my computer). I mean this is a part of the system folder and the one on the remote server should be used, right? I have the database set up as the remote database, and I don't have any local paths as far as I know....
So why does this happen, and what can I do about it?
Please help, this seems rather urgent. I'm a bit of a newbie to both php and CodeIgniter too, so a clear and simple answer would be greatly appreciated!
Local path as I see shows you file where your error happened, because your driver /Applications/MAMP/htdocs/expertinfo/system/database/drivers/mysql/mysql_driver.php possible on it's 88 line contain connect() function and it raise an exception
The problem is with your mydb24.surftown.se remote server, you should check your access credentials, etc. to find what exactly happened
Just an FYI, mysql_pconnect is usually a bad practice on shared hosting (you can see why here:http://stackoverflow.com/questions/1830830/advantages-disadvantages-of-pconnect-option-in-codeigniter)
You might just disable pconnect on application/config/database.php and see the error going away as your connections will be realluy lower.
For the quote: "mysql_pconnect is usually a bad practice on shared hosting".
I changed to use mysql_connect. It made no difference.

PHP: Can pcntl_alarm() and socket_select() peacefully exist in the same thread?

I have a PHP CLI script mostly written that functions as a chat server for chat clients to connect to (don't ask me why I'm doing it in PHP, thats another story haha).
My script utilizes the socket_select() function to hang execution until something happens on a socket, at which point it wakes up, processes the event, and waits until the next event. Now, there are some routine tasks that I need performed every 30 seconds or so (check if tempbanned users should be unbanned, save user databases, other assorted things).
From what I can tell, PHP doesn't have very great multi-threading support at all. My first thought was to compare a timestamp every time the socket generates an event and gets the program flowing again, but this is very inconsistent since the server could very well sit idle for hours and not have any of my cleanup routines executed.
I came across the PHP pcntl extensions, and it lets me use assign a time interval for SIGALRM to get sent and a function get executed every time it's sent. This seems like the ideal solution to my problem, however pcntl_alarm() and socket_select() clash with each other pretty bad. Every time SIGALRM is triggered, all sorts of crazy things happen to my socket control code.
My program is fairly lengthy so I can't post it all here, but it shouldn't matter since I don't believe I'm doing anything wrong code-wise. My question is: Is there any way for a SIGALRM to be handled in the same thread as a waiting socket_select()? If so, how? If not, what are my alternatives here?
Here's some output from my program. My alarm function simply outputs "Tick!" whenever it's called to make it easy to tell when stuff is happening. This is the output (including errors) after allowing it to tick 4 times (there were no actual attempts at connecting to the server despite what it says):
[05-28-10 # 20:01:05] Chat server started on 192.168.1.28 port 4050
[05-28-10 # 20:01:05] Loaded 2 users from file
PHP Notice: Undefined offset: 0 in /home/danny/projects/PHPChatServ/ChatServ.php on line 112
PHP Warning: socket_select(): unable to select [4]: Interrupted system call in /home/danny/projects/PHPChatServ/ChatServ.php on line 116
[05-28-10 # 20:01:15] Tick!
PHP Warning: socket_accept(): unable to accept incoming connection [4]: Interrupted system call in /home/danny/projects/PHPChatServ/ChatServ.php on line 126
[05-28-10 # 20:01:25] Tick!
PHP Warning: socket_getpeername() expects parameter 1 to be resource, boolean given in /home/danny/projects/PHPChatServ/ChatServ.php on line 129
[05-28-10 # 20:01:25] Accepting socket connection from
PHP Notice: Undefined offset: 1 in /home/danny/projects/PHPChatServ/ChatServ.php on line 112
PHP Warning: socket_select(): unable to select [4]: Interrupted system call in /home/danny/projects/PHPChatServ/ChatServ.php on line 116
[05-28-10 # 20:01:35] Tick!
PHP Warning: socket_accept(): unable to accept incoming connection [4]: Interrupted system call in /home/danny/projects/PHPChatServ/ChatServ.php on line 126
[05-28-10 # 20:01:45] Tick!
PHP Warning: socket_getpeername() expects parameter 1 to be resource, boolean given in /home/danny/projects/PHPChatServ/ChatServ.php on line 129
[05-28-10 # 20:01:45] Accepting socket connection from
PHP Notice: Undefined offset: 2 in /home/danny/projects/PHPChatServ/ChatServ.php on line 112
pcntl_alarm and socket_select can coexist, but you need to be aware of how to do it right.
In particular, if the alarm goes off while socket_select() is waiting, then after the alarm is handled the socket_select() will return immediately with an error indication. The error is "Interrupted System Call", which is what you're seeing in the output. You need to specifically check for that error, and retry the socket_select().
Alternatively, you can just forget about using the alarm and instead use the timeout facility of socket_select(). This is what the tv_sec parameter is for - it gives a timeout in seconds, after which the socket_select() will return even if no sockets are ready. You can then do your regular processing.

Categories