Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7054627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:39:00+00:00 2026-05-28T03:39:00+00:00

How do I queue functions in PHP? I need something that works just like

  • 0

How do I queue functions in PHP? I need something that works just like WordPress’s add_action system. I want enqueue function which then runs when the time is right.

Edit

This seems to work perfectly. Anyone got any tips to improve my code?

 $enqueued_actions = array();

 /**
  * Enqueue an action to run at a later time.
  * @param string  $hook The hook name.
  * @param obj  $func The function object.
  * @param integer $imp  The level of importance from 0-9
  */
 function add_action($hook, $func, $imp = 0) {

     global $enqueued_actions;

     $enqueued_actions[$hook][] = array('func' => $func, 'imp' => $imp);
 }

 /**
  * Run the enqueued actions with the correct hook.
  * @param  string $hook Hook name.
  */
 function run_action($hook) {

     global $enqueued_actions;

     $actions = $enqueued_actions[$hook];

     for($i = 0; $i < 9; $i++) {
         foreach($enqueued_actions[$hook] as $action) {
             if($action['imp'] == $i) {
                call_user_func($action['func']);
            }
         }     
     }

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:39:01+00:00Added an answer on May 28, 2026 at 3:39 am

    You are on the right track here. You might want to make the hooks persistent, though, i.e. saving the hooks into a database, a CSV file, an XML object model, etc.

    Also, you might want to introduce a function for the sake of calling all the actions that have been latched to a certain hook, something like call_actions($hook);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Queue object that I need to ensure is thread-safe. Would it
I have a priority queue implementation in C# that I want to add a
I have a list/queue of 200 commands that I need to run in a
I've got a PHP script in the works that is a job worker; its
PHP provides a mechanism to register a shutdown function: register_shutdown_function('shutdown_func'); The problem is that
I'm on an ubuntu virtual server. Sendmail works through php's mail() function but it
I am completely perplexed with how my Queue is function. I am attempting (and
The default stl priority queue is a Max one (Top function returns the largest
Does anyone know why std::queue, std::stack, and std::priority_queue don't provide a clear() member function?
I have a Queue<T> object that I have initialised to a capacity of 2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.