Running processes in the background - Accessing same script twice

Asked

Viewed 2,103 times

3

I have a PHP script that aims to integrate with a third party system.

Basically, my script sends image and text files to the client’s ftp.

To ensure processing for a long time, I use the following instruction:

ignore_user_abort( true ); // Não interrompe o script em caso de perda de conexão
set_time_limit( 21600 ); // Time out após 6h

Also, to prevent double processing, a file is created at the beginning which, at the end of the script, is deleted.

So that if the file exists, it is because the process is running.

The script works beautifully.

The problem is that this script is called via AJAX by my system (asynchronously), and is then run in the background. But then, once started the process, I can’t do anything else on the system until it ends, unless I open it in another browser or using another protocol (one with www and the other without).

This is browser limitation, or is something that can be configured on/php server?

Thanks in advance for the help!

Obs.: There are several processes running in the background in the system, but this is the only one that stops the other processes.

  • 2

    You’re making ajax synchronous?

  • @Sergio Access is naturally asynchronous. In fact the system does several processes in the background... this is the one that blocks other processing.

  • 1

    @Szag-Ot, ok, can you explain further "I can’t do anything else in the system until it ends"? Who is blocking other processing?

  • @Sergio, any process/link/page of the same domain that you try to access, is not opened until the above mentioned process has ended. The browser is waiting. And in the case of other processes in the background, they are not executed until the end of this.

  • busy socket, when releasing a vc uses, or alias, which is the case when you use www or 127.0.0.1 for example.

1 answer

3


Okay guys, I appreciate you taking the time to help me (especially @Sergio), but I found the solution.

The problem lies in a simple mistake. I had done it before, but it was a long time ago... I ended up remembering and I really found myself to be the following:

I open a session at the beginning of the process (with session_start(), naturally) but do not close it at any time (with session_write_close()).

It is not about closing or destroying the session. It’s just a matter of getting informed for the script that you no longer need it after a certain point.

Once placed session_write_close() right after the line making use of the session for the last time, the problem no longer occurs.

Thank you again!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.