How to set php ignore user abort in Server Connect?

Hi I just want to know how to I set php ignore user abort in my server connect script?

'ignore_user_abort(true)'

I have a mailer action with while loop that I need it to keep running even when user disconnected or close the browser.

Thanks for insight.

Might you be better running it as a CRON job if possible?

Yes but I'm asking what I don't know.

Just an idea, not sure if it will work but try

Create a php file with the content:

<?php
ignore_user_abort(true);
set_time_limit(0);
?>

Then within your api script, run it from an API action i.e.
Url = https://mydomain/path_to_script/flename

at the start of your mailer script.

Sorry, maybe I'm a little confused, but I always thought that sc won't abort as:

@franse You're confused because you're applying NodeJS advice to PHP :grin:
Edit: My bad, you're right, nice catch!

@Hyperbytes the PHP script you mentioned will only run those two instructions, if you run it from an API Action it'll just return an empty response body, it'll not influence the main PHP script. However, if you copy those two lines to the mailer's PHP script, maybe that could work

Edit 2:
Even if @franse is correct, @Hyperbytes code contains the set_time_limit instruction, so it's still useful

So long now since i did anything serious with php i forgot you could edit php code into api actions

Thanks, guys, for the inputs. I've tested it, and I think the script is not being aborted if I close the page. The only problem now is that the page cannot be navigated away from when the script status is 'pending'. That's probably another issue that I need to fix, but I got the idea (that it was a bad idea, lol).

Oh! That issue is tricky to solve... It's related to sessions, only one script can be running at the same time for the same session... This is a PHP thing.

Well, you have to try other ideas :sweat_smile:

Indeed, I finally managed to take care of it.

To sum up:

*The Server Action (SA) API isn't aborted by default if I close the page while it's pending, so there's no need to modify any code.
*I managed to work around the session locking or synchronous script issues (whatever they are) by using the Fetch API. Instead of using a dynamic event, I use a static event on success/done to call the SA mail API using a JavaScript function. This way, my mail script can run in the background without interfering with the current page.

1 Like

Hi hi.,. can you please explain this step a bit more please..


I managed to work around the session locking or synchronous script issues (whatever they are) by using the Fetch API.


Maybe a screenshot of your workflow UI please?