简体   繁体   中英

PHP simple parser to run only once a day

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.

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/

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

在此输入图像描述

You can contact with your hosting server but temporary solution for this kind of problem is to use cronjob service there are lot of free cronjob service out there in web. you can try those service .

I used this kind of service while creating a DDoS bot .. :p ..

You can use these cronjob service but there are more ...

  1. https://www.setcronjob.com/
  2. https://www.easycron.com/

search in google with "Cron job service" you'll find thousands of service like this

Happy coding :)

I use windows task-schedule. To execute a .php script you can either insert it like this or create a .bat file and execute it through there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM