php - Trigger self-execution in autonomous task

448

I have a file 'example.php' and it's execution time may vary. It needs to be executed as often as possible and as fast as possible. Therefore I'd like to trigger itself after successful execution. (without using cronjobs) I wouldn't like to run multiple, independent instances of 'example.php' either.

If I used something like header('example.php') or file_get_contents('example.php'), I needed to take care about max_execution_time, maybe even buffer sizes etc. as it would be interpreted as a single, never-ending execution task, right?

So what I'm looking for is something like the go function in Golang. Just execute 'example.php' and exit/move on. Ideally 'example.php' would be executed as an autonomous task like it was triggered from a cronjob/user.

What is best practice in this case? Thank you in advance.

739

Answer

Solution:

Okay, I found a solution myself. So for anyone who's facing something similar some time in the future:

I use curl with CURLOPT_TIMEOUT_MS set to a ridiculous low timeout value. This way an autonomous task will be created and curl will abort the request before an answer is sent. The caller instance of 'example.php' can be terminated right after, while the called instance of 'example.php' is still trying to send a valid response.

People are also looking for solutions to the problem: php - Symfony2 Login SHA512 - Bad Credentials

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.