I'm looking for an option to run the app in the background (when app is not active, or a screen is off), but haven't found anything for NativePHP. I've checked a couple of open-source apps (https://github.com/NativePHP/awesome-nativephp) but haven't found anything similar to my request. Is it possible?

Actually it's used a simple ping request that returns the actual state of the process:

function checkState() { fetch('/cgi/ch_ref.php') .then(response => response.text()) .then(data => { // TBD: handle response data }) .catch(error => { console.error('Ping error:', error); }); } const timerInterval = setInterval(checkState, 30000);

@vite(['resources/js/ping.js'])

FieryCat's user avatar

1

It depends on what you mean by "background".

If the NativePHP application process is still running (the window is open), you can simply use a timer/polling mechanism like the one you already have:

setInterval(checkState, 30000);

However, if the application is closed or suspended, no PHP/JS code inside the app will continue running. In that case the task must run outside the UI process (for example a cron job, queue worker, or OS scheduled task), and the NativePHP app should only query the current state when it opens.

Oscar Prieto's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.