Automatically execute a PHP script

715

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 ?

260

Answer

Solution:

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

592

Answer

Solution:

Using the following:

  • Usecron to automate the task (more info)
  • If you wish to have the page as a web page you'll want to usewget 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.)

People are also looking for solutions to the problem: php - Remove new lines from string and replace with one empty space

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.