Search code examples
phpsessioncurlcronrequest

Pass information between CronJobs


I have a Cron which gets executed by EasyCron once every 10 minutes and throws a cURL request (with PHP) to update some users' data.

The problem is that the website that I get the information from blocks anyone who makes that request after some time.

So I have to do pass some data (an integer is enough) to the next Cron depending on the result of my CronJob. If I get an error, I stop requesting that information for some time to prevent my website from being blocked for a day or more.

Since I can't use sessions, a workaround could be a blank file with only a number in it, but I'm searching for a cleaner solution... A way to pass the information via GET request or a sort of SESSION depending on the result.

Thank you for any response.


Solution

  • You have multiple options;

    passing the variable in a file

    In this case you would just put the values to the file and pass read it from the other cron job. If you also need to keep the type, then you can store the variable type as a string, and translate it to type in the other cron job.

    passing the variable to a DB

    Here you store the variable in a database, and read it in the similar way from the other cron job

    passing the variable using UDP port or socket file

    These are popular ways to do it. However if you implement it for socket file you wont be able to use it on windows, only on linux environments

    make the variable an environment variable

    for example: export VARIABLE, and in the other script you would take this value, then clear it.