Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/257760-create-phpajax-job-queue/
Share on other sites

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 ... 

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)

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.