Pierre Espenan
Pierre Espenan

Reputation: 4066

Automatically execute a PHP script

I am currently developing a website. Users can post ads which are added in a database. I would like to delete these ads when they are more than 60 days old. To do so, I will write a PHP script which will find such ads and delete them from the database.

Right, it's easy. But how do I execute this script without loading a page every day in my browser ? How do I ask to my server to execute it automatically regularly ?

Thanks !

PS : I am on a shared server, not a dedicated one. Does it make cron use not possible ?

Upvotes: 2

Views: 8954

Answers (2)

Prisoner
Prisoner

Reputation: 27638

Using the following:

  • Use cron to automate the task (more info)
  • If you wish to have the page as a web page you'll want to use wget to load the web page (more info)
  • Alternatively, use PHP from the command line by doing something like /path/to/php /path/to/script.php - you need to make sure you give this file (script.php) executable permissions. (more info)

Edit: You can use cronjobs on a shared server, what control panel is available to you? (cPanel, Plesk, etc.)

Upvotes: 4

Is it Unix/BSD/Linux hosting? Then you are after cron jobs.

Upvotes: 5

Related Questions