_Jim
February 18, 2022, 3:21pm
1
I am trying to setup a cronjob but cannot get it to work because of the includes…
I have read that you can change from whick directory the cronjob is executed but my host told me the cd command is not available in directadmin (the server software).
Is there a different solution that you can think of to make cronjobs with includes work?
Dave
February 18, 2022, 3:27pm
2
Do you have access to SSH on the host machine? You should be able to do this via shell access with sudo permissions.
_Jim
February 18, 2022, 3:43pm
3
Hi Dave,
Yes I found the ssh setting and enabled it.
Can you tell me more or point me to a tutorial or something?
Dave
February 18, 2022, 8:29pm
4
This should help to get you on your way:
Plenty of guides on how to do this. Plus a fair few results in the Community search:
https://community.wappler.io/search?q=cron
_Jim
February 18, 2022, 10:46pm
5
Thanks Dave.
I am on windows. Does that work?
Dave
February 18, 2022, 11:33pm
6
What is the server architecture you’re hosting on @_Jim ?
I’m not familiar with Windows hosting at all unfortunately (we always opt for Linux)…
A quick search finds the following that may be of help:
Dave
February 18, 2022, 11:36pm
7
Looking at Directadmin it only appears to be available on Linux:
https://docs.directadmin.com/getting-started/installation/overview.html
So that may answer my above question… In that case my original reply above, regarding cron jobs, should be what you need to check out.
Apple
February 18, 2022, 11:38pm
8
Maybe something like this:
bash -c "cd /home/mydirectory && php cron.php"
By the way, DirectAdmin has a cronjob page, you don’t need to use SSH:
2 Likes
Dave
February 18, 2022, 11:43pm
9
Just as a note of precaution be very careful what interval you set to run your cron jobs as too often could cause a dramatic repercussion for your servers performance, some hosts may disable your jobs from running if this is the case…
_Jim
February 19, 2022, 12:34am
10
Thanks all for jumping in
My hosting is not windows… It’s appache/mysql php…
My work computer is windows.
@Apple yes directadmin has cronjobs. But I cannot use the cd (change directory) command (I was told) so that’s why I ask for a different solution.
But if you think it is possible, I’d love to hear
Apple
February 19, 2022, 12:45am
11
Perhaps what the tech meant is you couldn't use "cd" in a cronjob. But I wrapped it inside the command "bash", so it should be good (neat trick I learned somehow)
_Jim
February 19, 2022, 10:03pm
12
Well the bash command did something. No more include errors.
New error: undefined index
{"code":0,"file":"\/home\/mynftees\/domains\/mynftees.nl\/public_html\/dmxConnectLib\/lib\/core\/Request.php","line":26,"message":"Undefined index: REQUEST_METHOD","trace":"#0 \/home\/mynftees\/domains\/mynftees.nl\/public_html\/dmxConnectLib\/lib\/core\/Request.php(26): exception_error_handler(8, 'Undefined index...', '\/home\/mynftees\/...', 26, Array)\n#1 \/home\/mynftees\/domains\/mynftees.nl\/public_html\/dmxConnectLib\/lib\/App.php(36): lib\\core\\Request->__construct(Object(lib\\App))\n#2 \/home\/mynftees\/domains\/mynftees.nl\/public_html\/dmxConnect\/api\/floor_loop.php(5): lib\\App->__construct()\n#3 {main}"}
Apple
February 19, 2022, 10:31pm
13
Undefined index: REQUEST_METHOD
So, turns out you can't call this script directly. You have to use curl instead:
curl http://yourwebsite.com/cron.php
This is because $_SERVER['REQUEST_METHOD']
doesn't exist when called through the command line, so you have to call it through HTTP
curl is a command line tool to perform HTTP requests
1 Like
_Jim
February 19, 2022, 11:09pm
14
Thanks Apple
The curl method works great!
Maybe not as efficient but it works