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.

Multiple API Calls possible?

Discussion in 'cPanel Developers' started by bmett, Aug 16, 2010.

  1. bmett

    bmett Well-Known Member

    Joined:
    Aug 5, 2010
    Messages:
    63
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Brisbane, AU
    Hi there,

    I successfully integrated the cPanel API in our custom CMS and am quite happy how it is working.
    At one stage one page does many API calls at once to display all email addresses, forwarders and autoresponder for a given account. Sometimes for more than one account which multiplies the calls even more.
    Unfortunately our mail-server is still in the states (we are in Australia) and the response time is a bit unsatisfactory (Up to 5 seconds).
    The mentioned page (with all the calls) has to load regularly on a daily usage basis and thats why I want to try to reduce that loading time.

    At the moment every single API call has its own authentication. Is there a way to send multiple calls at once with only one authentication? Or maybe you guys have some other tips to speed up the response time.

    I hope what I wrote is understandable and not written to confusing ;)

    Cheers,
    Bjorn
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Bjorn,

    Firstly, there's not a multi-call per auth.

    If you're using the xml-api PHP client class, you're really not accruing that must extra overhead on the client side for the auth. process; that info is just in the headers. And the server side auth code is really inexpensive. But, I get what your saying. I've often dreamt of something like a call stack...but it's just not in the cards...hint-hint, a feature request might be in order ;)

    There's two things that jump to mind:

    1) client-side caching in your script. If you're polling those queries often (like more than a few times a minute, and the data is not likely to chance in 20-30 seconds, you might implement something to store those results. I'm pretty sure all the major PHP frameworks have caching classes/objects nowadays. Provided your code license allows it, you could incorporate one of those without having to develop one yourself.

    2) Write a custom API call that can perform the multiple calls and return the data to you client side. Take a look at the doc for writing custom modules, WritingCpanelModules < DeveloperResources/ApiBasics < TWiki . Custom modules can be call through the xml-api just like any other cPanel module

    The second option will probably get the performance that you desire since I think all your time is most likely being eating during transmission of the multi http requests. It may be too much of a learning curve to do a custom module if you're not familiar with Perl or just beginning with cPanel API calls. Nevertheless, I think you'll see the best return for your efforts with that choice :)

    I just thought of another option...you could create a dumby html file somewhere in the x3/ directory (or whichever theme you're using) that makes the API calls with cpanel tags (just like ordinary cPanel pages). The page would need to apply some sort of structure between the calls so you could parse the data on the client side in a clean way. It's not the best option, but it's worth considering...especially now that TemplateToolkit is available within API2 cPanel tags, UsingCpttTags < AllDocumentation/AutomationIntegration < TWiki; you should be able to easily structure the returning text in a manner that can be parsed.

    Cheers,
    -DavidN
     
  3. bmett

    bmett Well-Known Member

    Joined:
    Aug 5, 2010
    Messages:
    63
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Brisbane, AU
    HI David,

    Thanks for your thorough reply. It's really appreciated.

    I'll have to see if I find the time to get into writing a custom API call. But I think the main reason for the delay is (as you said) the transmission time of the multiple requests.
    It's manageable for now and I successfully reduced the number of multiple calls so that we can work with the system.

    Your idea of a client-side caching sounds very interesting to me. Especially because the data we get through the calls doesn't change that often.

    Thanks again for your time. I hope I can find some myself to look deeper into that issue Any results will be posted here :)

    Cheers,
    Bjorn
     
Loading...

Share This Page