Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating schedule task without Cron job

Tags:

php

mysql

cron

Scheduled task needs to be created but its not possible to use Cron job (there is a warning from hosting provider that "running the cron Job more than once within a 45-minute period is a infraction of their rules and could result in shutting down the account."

php script (which insert data from txt to mysql database) should be executed every minute, ie this link should be called http://www.myserver.com/ImportCumulusFile.php?type=dayfile&key=letmein&table=Dayfile&file=./data/Jan10log.txt

Is there any other way?

like image 761
Marko Avatar asked Dec 05 '22 06:12

Marko


2 Answers

There are multiple ways of doing repetitive jobs. Some of the ways that I can think about right away are:

  1. Using: https://www.setcronjob.com/

Use an external site like this to fire off your url at set intervals

  1. Using meta refresh. More here. You'd to have to open the page and leave it running.

  2. Javascript/Ajax refresh. Similar to the above example.

  3. Setting up a cron job. Most shared hosting do provide a way to set up cron jobs. Have a look at the cPanel of your hosting.

like image 65
Santosh Achari Avatar answered Dec 17 '22 22:12

Santosh Achari


if you have shell access you could execute a php script via the shell

something like this would be an endless loop, that would sleep 60 seconds execute, collect garbage and repeat until the end of time.

while(true) {
    sleep(60);
    //script here


    //end your script
}

or you could do a "poor mans cron" with ajax or meta refresh. i've done it before. basically, you just place a redirect with either javascript or html's meta refresh at the beggining of your script. access this script from your browser, and just leave it open. it'll refresh every 60 seconds, just like a cronjob.

yet another alternative to a cronjob, would be a bash script such as:

#!/bin/bash
while :

do
sleep 60
 wget http://127.0.0.1/path/to/cronjob.php -O Temp --delete-after

done

all this being said, you probably will get caught by the host and get terminated anyway.

So your best solution:

go and sign up for a 5-10 dollar a month vps, and say good bye to shared hosting and hello to running your own little server.

if you do this, you can even stop using crappy php and use facebook's hhvm instead and enjoy its awesome performance.

like image 36
r3wt Avatar answered Dec 17 '22 22:12

r3wt