I have a question about performing a very long and resource intensive task within WordPress. Here is the scenario.
I have a plugin that allows users to run a task that takes a very long time and once completed will return the result back to the user.
The first thing I did was run the task via WordPress AJAX functions. This did not work since the site locked up to that user. Meaning that if the task was started then no other pages could be loaded from that user. I was able to get it to work where other viewers of the site would not be locked out but the original person who started the task was still locked out. Also, this created a dependency since the user was not able to close that window while the AJAX task was running since that would close the connection and stop the task.
The second solution I tried to come up with was to just create a single event via the wp_schedule_single_event() function. I was able to develop this and everything works fine but now the task that is being run via wp-cron is taking a lot longer, like 10 times as long, than the AJAX method. Also, I break up this large task into many smaller tasks and when the first task is run via wp-cron it stales for a while. Then once the first task finally completes it is able to run smoothly again until something happens and it stales out. This process repeats until all the sub-tasks are completed. I am not sure if there is throttling built into the wp-cron function, but I do not see the same speed as I did with the AJAX function.
Overall my main question is how can I create a wp-cron task that runs as fast an AJAX task?
Here a simile question that I asked on Stack Overflow for reference.