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

  • Home
  • SEARCH
  • 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 7647827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:33:35+00:00 2026-05-31T10:33:35+00:00

I’ve been building PHP tools with a MySQL backend. Using multi-curl I can run

  • 0

I’ve been building PHP tools with a MySQL backend. Using multi-curl I can run dozens and sometimes hundreds of each script concurrently on just one old PC (that now run the latest Ubuntu desktop). Each machine and each VM on each machine is capable of running dozens of concurrent instances.

As a result I rapidly run out of MySQL connections. When I upped the number of connections in MySQL I froze the quad-core machine I was using to host the MySQL server. Since then I’ve moved on to a scheme where I have a DB specific for managing requests of other DBs and using cron jobs that run for hours I maintain a few open connections per machine. At this point I’m still in the light testing phase and I haven’t attempted to make hundreds of simultaneous requests to see how the MySQL server handles it.

Instead I’ve run into another issue that I’ve tried several solutions for all with approx the same results. The issue is that of duplicate data being entered into the DB because I have concurrent instances of the tool running on different machines. For example, I feed a big chunk of new data into my DB and that data needs to have a few tasks performed on it such as linking an email address to a user profile. I’ve chosen to have a background cron process handle this a little at a time and each machine does it’s share every 5 minutes. Since they all start at the same time they all grab the same email data and filter it using the same logic about which email addresses are higher priority. Then each machine begins to do what needs to be done with the emails it picked. Since they all kick off at the same time they frequently appear to grab the exact same data and attempt to do the same linkings. This causes a primary key exception in the linkage table but not some of the others. So I end up with duplicate data in some tables and occasionally incomplete linkage.

I’ve tried randomizing the SELECT data so the machines are working on different data sets. However, this is of course sub-optimal with respect to what I’d like the tool to accomplish so I need to run the tool more often in order for certain tasks to get completed in the desired time frame. I’ve tried creating a flag in the DB that designates 1 server is actively using the data so all other servers should wait. This works sometimes but sometimes 2 machines are polling that flag at the same time. Since we are talking multiple machines I don’t flock will work. And from what I’ve read locking the table in the DB may not be a good solution either.

So I’ve come to StackOverflow for advice rather than continuing to beat my head against a wall.

== Update ==

Gearman looked like a great solution so I gave it the thumbs up as the answer. However, I was never able to get it working with my PHP install. I attempted several sets of suggestions/instructions online many of which never even got gearman installed. The suggestion of using apt-get install gearman-server did get gearman installed as far as I could tell – i.e. no errors were generated and gearmand would run. However, when I attempted to use gearman clients and workers in scripts I would get errors regarding not being able to find those classes.

After that I added a gearman.ini file to the correct directory. It had 1 line extension=gearman.so. This lead to a different error where PHP told me it couldn’t find gearman.so. I attempted to use sudo find / -name gearman.* to find gearman.so with no luck – it returned C files but not gearman.so.

At this time I’d really, really, really like to implement gearman but since I can’t get it to work I’m stuck with my hack and slash PHP code for implementing my distributed toolset. My “solution” to date is to create a flag that it set to “OCCUPIED” when 1 instance of the tool is doing something that would cause duplicate data issues. I have created 5 of the same flag with postfixes of _1, _2, … so that 5 instances can run concurrently. (I use the _1, _2, … to create an offset into the returned DB data so that no 2 tool instances are working on the same data set. In other words, if a SELECT statement would return 100+ rows and I only work on 10 at a time then _1 works on rows 1-10, _2 works on 11-20, … Not ideal but it should allow multiple servers to operate on the DB simultaneously without duplicate data being created.)

The DB API tool timeouts if it doesn’t see a result in 30 sec. The problem now is frequent timeouts when attempting to grab those flag states…

  • 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-31T10:33:36+00:00Added an answer on May 31, 2026 at 10:33 am

    You should use a queue system to insert each data-set as an item in the queue and use your distributed server setup to pull jobs from the queue and execute queries against the database. Using a queue will prevent multiple workers from working the same job.

    Take a look at Gearman for an example

    • http://gearman.org/#how_does_gearman_work
    • http://us.php.net/gearman
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.