Wait until a callback address is called

otorrillas

I am programming an educational web in PHP and JS and I interact with another webpage that corrects for me some programming exercises.
I don't know when this correction will finish, but this correction webpage calls a given address when the correction is available. Is it possible to wait for that result with PHP or JS and then do some stuff (not just showing the result to the user), even if the user closes the tab?

Thanks in advance.

STEP BY STEP explanation:

  1. A student is trying to do a programming exercise. The statement of the exercise is shown, as well as other details to complete it.
  2. When he thinks he has reached a solution, he uploads his code. Then, he can wait (or not) for the correction to finish.

    1. My web page uploads then the code file (with other files as well as an address to callback when it finishes) to the corrector webpage.
    2. I keep waiting until the callback is made.
  3. When the correction is finished, I do some stuff like assigning a grade to the student and, if he/she stayed on the same page, he/she can see details of the correction.

The correction is done by another webpage and I don't know when it would finish, but when it finishes it calls a given adress (for example: www.example.com/ex1sub1usr1 ).

The doubts are between step 2 and 3. It is possible to do all this process with PHP/JS? If not, what are the alternatives?

pentaphobe

Updated Answer

  • Create a PHP script on your server which updates your grade database when visited with a specially formulated URL, eg. http://yourserver.com/update.php?user=2429&sub=1&ex=1
    • specify this as the target URL when you submit for correction
    • if you are restricted to your /ex1sub1usr1 format then just use regex to parse the URL
  • When user refreshes (or returns to your site) the data should be appropriately pulled from your PHP backend

For bonus points, you could have your submission screen (or the entire website) intermittently poll another PHP script URL on your server (with XHR) for an "updated" flag, and live update the page.

Considerations

Your only major concern will then be ensuring that the form data (ie. their code) is submitted completely. Consider using XHR to submit your form data and temporarily enabling a window closure warning until upload is complete.


Original "Answer"

Since there isn't much information to go by here, I will have to make a few assumptions:

  • you presumably can't reliably spawn a process to watch the associated results address
  • you don't need to notify the user immediately (push notifications), but they need eventually see their result, eg. when they return to your page
  • results stay around for a while
  • as you mention, this must work even if the user closes the tab

Given this scenario, I would merely check the results page when the user returns to your site.

Just store the results address in session vars - either via PHP or a cookie - then when the user returns you can perform any unfinished checks and update accordingly.

NB: Should further information surface in the question I will gladly provide further details

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Wait until callback

From Java

AwaitFor doesnt wait the callback to be called

From Dev

Wait for a callback to be called in an async method

From Dev

Sequelize wait until loop finished with callback

From Dev

Wait until a callback ends to continue execution in Angular

From Dev

How to wait until Callback has data?

From Dev

FB Android-SDK: How to wait until callback of request is completed

From Dev

Javascript wait until last event fired in callback before proceeding

From Dev

Make instance wait until called functions are complete - Swift

From Dev

How do I disable a button until callback is called?

From Dev

I want my telegram bot wait until user answers with telebot and callback handler

From Dev

How to wait until a callback is finished to return from ES6 Proxy

From Dev

Trying to implement callback, or some way to wait until my get request is done. This is in node.js express

From Dev

how to wait in the thread until it receives connect callback from google Api client

From Dev

Wait until element is not present

From Dev

Angularjs wait until

From Java

Wait until flag=true

From Dev

Wait until an object is available

From Dev

Wait until function is finished

From Dev

wait until the page is loaded

From Dev

Wait until AlertDialog shows

From Dev

Wait until statement is completed

From Dev

Wait until variable equals

From Dev

Wait until DispatchWorkItem is done

From Dev

Android testcase wait for callback

From Dev

Wait for openParentApplication callback to complete

From Dev

NodeJS loop wait for callback

From Dev

Android testcase wait for callback

From Dev

Making forEach wait for callback

Related Related

HotTag

Archive