Home > Blockchain >  Stop PHP script execution through externally updated variable in Laravel 9
Stop PHP script execution through externally updated variable in Laravel 9

Time:11-04

I'm trying to stop the execution of an php script in runtime triggered by the user.

My planned approach is to make an ajax call to the server, setting a session variable which is then looked up by the first already running script every now and then to determine if the process should stop or continue running. Hope that makes sense:)
I already found some examples of people doing the same here or with files instead of sessions here.

Now my problem is that I would like to use the session for my approach instead of the solution doing it with temporary files and the mentioned approach with sessions doesn't seem to work for me in Laravel 9.

The result I'm looking for:

  1. start first php script (runs maybe 30 seconds)
  2. make ajax call to server & set session variable stop_execution = true
  3. the first php script which is still running detects the change in stop_execution === true & stops execution.

The behaviour I get:

  1. start first php script (runs maybe 30 seconds)
  2. make ajax call to server & set session variable stop_execution = true
  3. the first php script which is still running doesn't detect the change in stop_execution === true & runs until it finishes by itself.
  4. the next time I run the first php script again it immediately detects the change in stop_execution === true & stops execution.

My thought on why this is happening is that the session variables doesn't get refreshed inside the first script after checking them for the first time. Maybe there is a way to force pull all new changes from the session variables while the first script is running? Did somebody have the same issues with Laravel? It seems like this is working with session variables when not using Laravel. I think it has something to do with Laravel and how the sessions are handled.

I would appreciate any advice

  • Related