Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP simple parser to run only once a day

Tags:

php

cron

I am using the simple_html_dom script to parse a value from a website.

My code:

<?php

include('simpleparser/simple_html_dom.php');

$html = file_get_html('http://www.example.com');

foreach($html->find('strong') as $e)  // the tag that I am fetching
echo $e->innertext ;

?>

Now, I'd like to run this only once per day as the data, I am parsing updates only once every day.

I've read a couple of articles about the cron task, but can not get it to work. The examples seem to overcomplicate things and are not relevant to my case. My hosting plan has the cron scheduler disabled and no shell access and I don't know how else to set it up.

like image 871
alex351 Avatar asked Oct 13 '15 22:10

alex351


2 Answers

To create cronjob from the command line use:

#write out current crontab
crontab -l > mycron
# echo new cron into cron file | runs everyday at 22h
echo "* 22 * * * php /full/path/to/script.php" >> mycron
#install new cron file
crontab mycron
rm mycron

To create a cronjob using Parallels Plesk Panel, take a look at this answer


UPDATE:

I have no shell access and cronjob disabled in my Plesk Panel.

Use a online cronjob https://www.setcronjob.com/

like image 162
Pedro Lobito Avatar answered Sep 20 '22 06:09

Pedro Lobito


If there's really no way for you to setup a cron job on your hosting - you could also use some online service to trigger your script once in a while.

For example https://cron-job.org seems to do what you need

Attaching a sample of settings they provide

enter image description here

like image 28
Stas Parshin Avatar answered Sep 20 '22 06:09

Stas Parshin