i am new to cron jobs and i have done much searching on this topic but i couldn't understand it fully. can cron jobs access cookies or session variables?
thanks!
Sessions in PHP normally do use cookies to function. But, PHP sessions can also work without cookies in case cookies are disabled or rejected by the browser that the PHP server is trying to communicate with.
A cron job in PHP powered systems, in particular, is often used to ensure timely execution of important tasks including executing or scheduling a code snippet. They are often used for system maintenance.
The tick cycle in cron is to repeatedly sleep for a minute, or less if there is a job coming up. Immediately after emerging from the sleep, it checks the time and treats the result as one of these wakeupKind values: Expected time - run any jobs we were expecting.
A cron job won't be able to access cookies, since by definition it is not being invoked from a web browser request. Only the web browser stores a cookie, which contains the session id. No web browser, no cookie, no session.
Having said that, if you do know the session id somehow, you should be able to start the session manually by feeding the id into session_id()
before using session_start()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With