[case 66489] Live PHP API loosing connection after ~5 seconds.

pijulius

Member
Jan 31, 2009
7
0
51
Hi Everyone,

I was building a cPanel plugin and now that I have everything ready and started to do some real life tests I come across a very strange thing that I hope you can help me with.


Case:
1. I have a form in my cPanel plugin that allows one to upload a file
2. When a file is uploaded I decompress it on the other end and set up everything I need

Result:
Everything works perfectly if you have a file that is 1MB or so (meaning the upload only takes a few seconds).

Problem:
If you select a file that is over 5MB (or any file that takes more then 5 seconds to upload) it immediately throws the following error:
Warning: fsockopen() [function.fsockopen]: unable to connect to unix:///home/xxxx/.cpanel/live-engine-connector-_rVwM_7CvU.sock:-1 (Connection refused) in /usr/local/cpanel/php/cpanel.php on line 145
There was a problem connecting back to the cPanel engine. Make sure your script ends with .live.php or .livephp

Note:
I see that every time you refresh your page there is a new socket file coming from getenv('CPANEL_PHPCONNECT_SOCKET') and this file gets automatically deleted once your script finishes but because this error the socket file is kept in the /home/xxxx/.cpanel directory and it has the right permissions set (user/group/read) but it seems it's not usable anymore.


Could someone please help me out with this problem. It seems like a timeout for the socket meaning as the form is submitted the cPanel creates the socket for the php but till the php script starts to run (because it is waiting for the file upload) the socket gets reset or something like that?

Hope you can help.

Thanks!
Julius
 
Last edited:

cPanelNick

Administrator
Staff member
Mar 9, 2015
3,488
35
158
cPanel Access Level
DataCenter Provider
Code:
include("/usr/local/cpanel/php/cpanel.php");
$cpanel = &new CPANEL();
Make sure you create the cpanel object as soon as the php execution starts. If it does not connect to the cpanel within 5 seconds it will assume your program has crashed or failed and terminate it.
 

pijulius

Member
Jan 31, 2009
7
0
51
Thanks for the help cpanelnick but unfortunately that didn't help.

I have a file called inout.live.php and I added the code:
Code:
<?php
	require_once "/usr/local/cpanel/php/cpanel.php";
	$GLOBALS['CP'] = new CPANEL();
right to the top but still the same thing. I think the reason being the the php file isn't called at all till the file isn't upload as if it would be called you would end up running your code before the file is fully uploaded.

Could you please explain more on the 5 second limit for the sockets? where is it set, how can it be changed or made to open the socket only once the php script starts to run? how would I be able to upload a file without having this timeout "bug"?

Thanks again,
Julius
 

cPanelNick

Administrator
Staff member
Mar 9, 2015
3,488
35
158
cPanel Access Level
DataCenter Provider
I did some testing, and the timeout is too aggressive to allow for anything beyond a small file to be uploaded in php since php handles the file upload before it connects to the liveapi socket. I created case 66489 to increase this timeout to 10 minutes.
 

pijulius

Member
Jan 31, 2009
7
0
51
I did some testing, and the timeout is too aggressive to allow for anything beyond a small file to be uploaded in php since php handles the file upload before it connects to the liveapi socket. I created case 66489 to increase this timeout to 10 minutes.
Thanks Nick! this is exactly what I was hoping for and I think the 10 minute limit would be perfectly fine, that should allow us to upload pretty big files too so this would definitely solve the problem.

Could you please let me know when and in which version would this be implemented (I'm sure we will have to wait for a new update), also if possible could I somehow increase the limit manually till the new version is out?

Thanks again!
Julius
 
Last edited:

cPanelNick

Administrator
Staff member
Mar 9, 2015
3,488
35
158
cPanel Access Level
DataCenter Provider
Thanks Nick! this is exactly what I was hoping for and I think the 10 minute limit would be perfectly fine, that should allow us to upload pretty big files too so this would definitely solve the problem.

Could you please let me know when and in which version would this be implemented (I'm sure we will have to wait for a new update), also if possible could I somehow increase the limit manually till the new version is out?

Thanks again!
Julius
This has already been merged into 11.37/11.38 and should ship with the next release if it passes QA in time.
 

pijulius

Member
Jan 31, 2009
7
0
51
Thanks again Nick, and also thank you guys for being so prompt and understanding!

FYI: for now what I have done is created a separate php file (for e.g. upload.live.php) and that will wait for the upload to finish and then rename the uploaded file to a temporary location and then redirect to the real inout.live.php with the location of the file which will then start to parse the file and use the cPanel api without the timeout problem.
 

cPanelNick

Administrator
Staff member
Mar 9, 2015
3,488
35
158
cPanel Access Level
DataCenter Provider
Thanks again Nick, and also thank you guys for being so prompt and understanding!

FYI: for now what I have done is created a separate php file (for e.g. upload.live.php) and that will wait for the upload to finish and then rename the uploaded file to a temporary location and then redirect to the real inout.live.php with the location of the file which will then start to parse the file and use the cPanel api without the timeout problem.
This change was published in 11.37.0.6. It should also go out next time we update 11.36