The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'cPanel Developers' started by pijulius, Apr 24, 2013.

  1. pijulius

    pijulius Member

    Joined:
    Jan 31, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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
     
    #1 pijulius, Apr 24, 2013
    Last edited: Apr 24, 2013
  2. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    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.
     
  3. pijulius

    pijulius Member

    Joined:
    Jan 31, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  4. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,446
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
  5. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    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.
     
  6. pijulius

    pijulius Member

    Joined:
    Jan 31, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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
     
    #6 pijulius, Apr 25, 2013
    Last edited: Apr 25, 2013
  7. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    This has already been merged into 11.37/11.38 and should ship with the next release if it passes QA in time.
     
  8. pijulius

    pijulius Member

    Joined:
    Jan 31, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
  9. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    This change was published in 11.37.0.6. It should also go out next time we update 11.36
     

Share This Page