Help with cronjobs

hello everyone, pretty new to this hole thing was wondering if anyone could help explain to me how to set up a cronjob to basically run a php file on my site every 5 mins or so i can make it work by typing it into the url bar to test that the php script itself is fine i just dont know how to make a cron job to do it automatically. any help would be greatly appreciated

I think this video will explain it better than I could. Note there is a default setting for every 5 minutes in teh Common settings menu.

i watched that but sadly the interface is a little bit different for me mine only has 2 options one for minutes another for hours and then a text box to direct to a file for it to run, iv tried directing it to run the php script itself that does nothing i also tried writing a txt file with script in it which also doesnt work however if i take part of the script and run it in a URL myself it works fine. sorry this is probably not well worded and im not sure what im doing to start with

I don’t have much info, but you probably don’t have the correct file paths. For example, my cron.php file


	file_put_contents( $_SERVER['DOCUMENT_ROOT'] . '/test/cron.log', 'Chicken pulls the blanket', FILE_APPEND )


And in cron manager, the file path is

htdocs is your root directory.

Yeah iv tried that both with the /htdocs/ added directly after the web address and with it removed all together like you have in your example and neither works. however when i run the script manually by entering it into my urlbar i do have to include ?encode and then a bunch of characters afterwards for it to work but i dont think i can direct the cronjob to work like that because it accesses the php differently to how i access it by pasting it into url bar right?. i feel like i may have to accept defeat here and accept that id i do not have the knowledge required for to achieve this lol

With most hosting systems, the cron jobs are typically used to execute PHP on the command line. And like you expect, you would have to pass data differently than you would with a website.

However, with InfinityFree, it works more like a web cron. So basically, the cron job just requests a certain URL on your website at your defined frequency.

So if you have a cron job which you can access through your browser at, you can put my-app/scripts/cron.php in the box and it works the same.

Hi Admin thank you for trying to help me here especially as part of a free service, yes i can run the script in a browser window but only IF i add to the end of the url “?encoded=encoding key” however when i take this entire url and copy it into the command box of the cronjob field it adds it to the list of cronjobs but it never seems to run. when paste the exact same thing into my browser however it works fine. if theres any way to discuss this in a private message with you i would be happy to give you the full url so that you can see exactly what it is im trying to do.

once again thank you for your responses and help :slight_smile:

I’m sorry, but while I’m happy to answer questions on this forum, I do not typically engage in private discussions about any issue. I’m answering this question for you now, but also for other people in the future with similar questions, who may find this discussion relevant for them as well. That way, the forum also becomes somewhat like an extended knowledge base.

As for your issue specifically, how do you see exactly the cron job doesn’t run? Does your cron job have any logging to record when it was called?

Hello admin,

I do understand wanting to maintain answers on the knowledgebase for anyone else with the same problem. i was requesting private communication so that i could provide you specific details so you can reproduce the problem yourself, however i cannot include these in a public post as anyone could then access parts of the site that they should not be able to. nevertheless i will continue to explain as best i can.

the script calls for updates to several figures on the website therefore when it has ran successfully i would see these figures update on the website as expected additionally when invoking the “cronjob” through my web browser including the encoding key i receive a page that confirms which figures have been updated and when checking the main site i can see this reflected. however when i set this up as a cronjob through the Cpanel both with and without the encoded key and wait the required 5 minutes no updates are made to the website at all. which is how i know it has not worked.

I’d love to help you with this, but it’s a bit hard to verify whether a cron job has or hasn’t run based on side effects (updated figures) only.

Could you try to add a statement to the start of your code which logs something? You could write some data like a timestamp to a file or to a database. That might make it a bit easier to tell the difference between a cron job which didn’t run and one which didn’t complete successfully.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.