Ashwin
Ashwin

Reputation: 460

How to run PHP script in queue?

In my current task, when I selecting a large number of records and then changing their status or reassigning them, the system can slow to that point so user have to wait for some time to complete this operation.

So is there any way to put this process in queue so the process run in background and user can do their other tasks.

Thank you in advanced.

Upvotes: 3

Views: 880

Answers (5)

Hari Ramamurthy
Hari Ramamurthy

Reputation: 96

Need more information on how the queue is processed, you mean that the data that is being processed has nothing to do with the second process running after the first process? In that case I would run your script as

yourcommand > /dev/null 2>&1 &

this would let the process run in the background.

In the context of PHP, if it is speed that you are after, I would check if PHP has enough memory available. If yes, I would save the values in an array and use a foreach loop to manipulate data. Usually this works out faster.

More information is required.

Hari

Upvotes: 0

pomaxa
pomaxa

Reputation: 1746

Yes, for sure. If you would like to keep php script doing it job in background, and let user to play with your site. All you need to do, is send headers :

header("Connection: close");
header("Content-length: $size");

Is it what you are looking for?

Upvotes: 0

MaX
MaX

Reputation: 1344

You can choose from

  • Gearman

  • Beanstalkd

  • RabbitMQ

    Basically you can run any MessageQ system and then use STOMP(A standard protocol) to talk between processes.

Upvotes: 0

Manoj
Manoj

Reputation: 373

Use j-query ajax method and make user wait without making any actions.

Upvotes: 0

Brian
Brian

Reputation: 8616

Yup... have a look at Gearman:

http://gearman.org/index.php?id=getting_started

http://php.net/manual/en/book.gearman.php

Alternativley, if you don't fancy that, I have used the principle of this excellent 4-part tutorial many times to great effect:

http://squirrelshaterobots.com/programming/php/building-a-queue-server-in-php-part-1-understanding-the-project/

Upvotes: 2

Related Questions