1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Plugin Multithreading?

Discussion in 'Facepalm' started by HittmanA, Jul 10, 2017.

  1. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    So in my plugin I need to make an HTTP call (yes I absolutely must). When I submitted the plugin for review it was rejected because I do the HTTP call in the main thread. What is the best way to do an HTTP call outside the main thread?
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Use async task
    like mine: https://github.com/ThunderDoesPlugins/Twix/blob/master/src/Thunder33345/Twix/TwixFetcher.php
    Most of the code there are just for API support

    just try to curl exec under OnRun but keep in mind using threads have limitations, like dont pass $server or $plugin etc

    also calling things like set_time_limit() are not recommended and PMMP already called that + plugins will not be terminated by function running too long

    offtopic, your plugin should try to make things into function calls then nesting in onCommand, that make it more readable and API support, if you plan to have any
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.