Ortix Posted February 25, 2012 Share Posted February 25, 2012 Hi guys, I'm currently trying to design a PHP and AJAX driven job queue, very specific to my need but I need some guidance. This is the basic gist: I have several files on my server which can be browsed with a filemanager. Next to each file there is an upload button. Currently when clicked, it will invoke a php script which in turn runs a bash script. The bash script then in turn runs plowup to upload the file (Plowshare: a program which uploads/downloads files to/from filesharing hosts). The problem is that I want to expand this. As of now, if I click the upload button of 3 files, 3 uploads get initiated which I do not want. I want a queue. When the upload button is clicked I want a php script to run which initiates the upload (without the bash script, but that's not an issue). If a subsequent button is clicked that job needs to be placed in a queue. How would I do this? As in, how do I keep track of the jobs and how do i queue them? Also if I want to create a frontend which shows the jobs, how would I go about doing this? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/257760-create-phpajax-job-queue/ Share on other sites More sharing options...
jawef Posted February 27, 2012 Share Posted February 27, 2012 This is something that has to be done client side, with JavaScript. You could have an array of submit actions, when somebody presses a button if the array is empty submitting through AJAX else pushed in the array. When submitting with AJAX you can define a function to be called on AJAX response (with onreadystatechange). In that function if the array of actions isn’t empty use the first element to generate an AJAX request (and remove it from array) and so on… Of course I didn’t cover even the half of how to do it in real life, but that is just an idea ... Quote Link to comment https://forums.phpfreaks.com/topic/257760-create-phpajax-job-queue/#findComment-1321541 Share on other sites More sharing options...
Ortix Posted February 27, 2012 Author Share Posted February 27, 2012 I'm not quite sure why it has to be done clientside... The AJAX requests are not the issue here. The PHP job queue is. I did find a solution called gearman, but I can't get that to install (yet) but I want to be able to write this on my own. Basically I need to be able to queue PHP jobs/functions somehow where I use AJAX to request data on progress (but that's a whole other issue) Quote Link to comment https://forums.phpfreaks.com/topic/257760-create-phpajax-job-queue/#findComment-1321641 Share on other sites More sharing options...
thehippy Posted February 27, 2012 Share Posted February 27, 2012 User clicks 'Upload' to add file(s) to upload queue json controller gets queue object and pushes message(s) to queue In the background.... Write a scheduler (cron'd php) to check every n-minutes if there is a upload in progress else pop the next message (file to upload) in queue upload file (initiate bash script or w/e) The actual queue can be a simple database table or something more specialized like an AMQP server. Seems simple enough to me, am I missing something? Quote Link to comment https://forums.phpfreaks.com/topic/257760-create-phpajax-job-queue/#findComment-1321819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.