问题
I am creating a website for a client where they need the ability to generate 25,000 - 100,000 barcodes. I have licensed a software that generates the codes but it takes around 20 - 30 minutes to generate an order of say. 60,000 barcodes.
So my question is this...
Would it be possible to use the set time limit function in php set to zero (no time limit) and then pass the variables to the library with Ajax and use the ignore_user_abort function. This way essentially this is what would happen:
Customer chooses barcode qty and type, they check out and after the payment gateway sends back a response of SUCCESSFUL, then we run an ajax request that sets the time limit to UNLIMITED and then tells the script to run even if the user closes their browser or exits the page. This way the server processes the order and it doesn't matter if it takes 2 seconds or 45 minutes. When the order is done the client can refresh their account and they would see their order.
Am I just dreaming to think that this sounds like a good idea or would it be a viable solution? I don't have any experience in my years of coding with php queue systems, so I don't want to have to create one unless I absolutely have to.
回答1:
I would look at using something like Gearman ( http://gearman.org/index.php ).
This would also be separate to the CI app ... CI will then use Gearman to process a queue...
回答2:
Don't depend on one long-running PHP instance. Especially if it's tied to the user/browser in any way. Properly separate the backend system from ephemeral processes like web server responses.
Make a proper queue-worker system. Put all orders into a queue (database, flat file, whatever) and have a worker take orders from the queue one by one, process them, update the result. The worker can be a cron job, a daemon process, an endless looping PHP script (which is restarted by a monitor if it crashes) or whatever else. You can also look into AMQP, ZeroMQ or similar queuing/messaging systems.
回答3:
Try using CLI at backend, it doesn't have timelimit by default.. http://php.net/manual/en/info.configuration.php#ini.max-execution-time
What I mean in 3 steps..
First save the ORDER at your database..
Second!!! Set crontask to run each minute, to take and proccess 1 order. When order is ready (after 30minutes) update the database with download links or what ever you return as responde and end the crontasks.
Third. After his order is ready show to user at some page the result.
来源:https://stackoverflow.com/questions/13065975/php-queue-system-with-codeigniter-how