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 6197409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:49:00+00:00 2026-05-24T03:49:00+00:00

Hey there I am having some CPU spikes due to PHP script I run

  • 0

Hey there I am having some CPU spikes due to PHP script I run every 30 mins.
Script sends twits to signed up twitter users everyday and there are a lot of users.
So basically when PHP script sends out twits it causes a CPU spike.

I am asking for a direction on how should I handle this situation. Thanks a lot.

  • 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-24T03:49:00+00:00Added an answer on May 24, 2026 at 3:49 am

    Usleep

    Just a tiny little usleep will return the CPU to other available process(CPU scheduling).

    Hog

    Take this simple script for example:

    <?php
    
    for ($i=0;$i<1000000;$i++) {
        echo "$i\n";
    }
    

    This process consumes 20% of my CPU-time on average.

    Schedule

    This simple script only consumes 10% CPU-time on averqage.

    <?php
    
    for ($i=0;$i<1000000;$i++) {
        echo "$i\n";
        usleep(100);
    }
    

    Of-course this script does take a little longer, but the CPU is better scheduled. The longer you usleep the better the CPU can schedule. usleep(1000) for example only used 2% CPU-time.

    I tested this on my Ubuntu Box

    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 10.10
    Release:    10.10
    Codename:   maverick
    

    Message Queue

    Also your operating system is very good at scheduling processes(of course that process needs to be friendly to your CPU) so I would advice you to use a message queue to speed up your work(sending tweets). For example Redis can also be used as a message queue or beanstalkd. Run a couple of worker processes which process work(sending out tweets). As a bonus you don’t incur the price of spawning processes which is relative expensive. On the web there is more than enough information available using message queue.

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

Sidebar

Related Questions

Hey there, I am really having some issues overriding the shipping block in the
hey there, Im having problems displaying my results in this program but the program
Hey there! I'm doing this project and right now I'm trying to: create some
hey there i am having problem i have List<List<memoryCard>> that i want to show
Hey all of you PHP geeks, and hackers, if some of you listen ;o)
Hey everyone. This seems easy enough, but for some reason I'm having a hard
Hey all, I'm having some trouble setting up my grails application. Running the app
Hey guys I'm having trouble looping through some XML. Im trying to capture the
Hey, I'm having some trouble using the QuickBase API from Python. From the QuickBase
Hey there. Java beginner here :) Well, I'm having a few troubles with this

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.