I'm looking for an option to run the app in the background on mobile O/Sses (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 (e.g. https://github.com/NativePHP/awesome-nativephp) but haven't found anything similar to my request. Is it possible?
It uses 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'])
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