Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:27:42+00:00 2026-05-25T21:27:42+00:00

I have created a php/mysql scraper, which is running fine, and have no idea

  • 0

I have created a php/mysql scraper, which is running fine, and have no idea how to most-efficiently run it as a cron job.

There are 300 sites, each with between 20 – 200 pages being scraped. It takes between 4 – 7 hours to scrape all the sites (depending on network latency and other factors). The scraper needs to do a complete run once daily.

Should I run this as 1 cron job which runs for the entire 4 – 7 hours, or run it every hour 7 times, or run it every 10 minutes until complete?

The script is set up to run from the cron like this:

while($starttime+600 > time()){
   do_scrape();
}

Which will run the do_scrape() function, which scrapes 10 urls at a time, until (in this case) 600 seconds has passed. The do_scrape can take between 5 – 60 seconds to run.

I am asking here as I cant find any information on the web about how to run this, and am kind of wary about getting this running daily, as php isnt really designed to be run as a single script for 7 hours.

I wrote it in vanilla PHP/mysql, and it is running on cut down debian VPS with only lighttpd/mysql/php5 installed. I have run it with a timeout of 6000 seconds (100 minutes) without any issue (the server didnt fall over).

Any advice on how to go about this task is appreciated. What should I be watching out for etc..? or am i going about executing this all wrong?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:27:42+00:00Added an answer on May 25, 2026 at 9:27 pm

    There’s nothing wrong with running a well-written PHP script for long periods. I have some scripts that have literally been running continuously for months. Just watch your memory usage, and you should be fine.

    That said, your architecture is pretty basic, and is unlikely scale very well.

    You might consider moving from a big monolithic script to a divide-and-conquer strategy. For instance, it sounds like your script is making synchronous requests for every URL is scrapes. If that’s true, then most of that 7 hour run time is spent idly waiting for a response from some remote server.

    In an ideal world, you wouldn’t write this kind of thing PHP. Some language that handles threads and can easily do asynchronous http requests with callback would be much better suited.

    That said, if I were doing this in PHP, I’d be aiming at having a script that kicks of N children who grab data from URLs, and stick the response data in some kind of work queue, and then another script that pretty much runs all the time, processing any work it finds in the queue.

    Then you just cron your fetcher-script-manager to run once an hour, it manages some worker processes that fetch the data (in parellel, so latency doesn’t kill you), and stick the work on the queue. Then the queue-cruncher sees the work on the queue and crunches it.

    Depending on how you implement the queue, this could scale pretty well. You could have multiple boxes fetching remote data, and sticking it on some central queue box (with a queue implemented in mysql, or memcache, or whatever). You could even conceivably have multiple boxes taking work from the queue and doing the work.

    Of course, the devil is in the details, but this design is generally more scalable and usually more robust than a single-threaded fetch-process-repeat script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started PHP and MySQL and have created a login form and
I have created an admin panel for a client in PHP, which requires a
PHP mysql database I have created a follow on question to this one here
I have created a custom PHP script which uploads information submitted by a form
I have created a MySQL database wherein users add information via PHP. Each time
Hello I have a website. created using php,mysql. I want to set a limit
I have a gallery of products that is dynamically created using php and mysql
hi i created a simple php/mysql/Ajax chat application and I have a few questions.
I have created a file called 'userhistoryreport.php'. It will be setup to run once
I have a server (VPS) that hosts numerous PHP / MySQL websites. Most are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.