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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:30:01+00:00 2026-06-11T08:30:01+00:00

Could you please help me to customize the following cron script in PHP. The

  • 0

Could you please help me to customize the following cron script in PHP. The script is creating many background process in the server. After a day the server is going busy and MYSQL server is crashed.

What is wrong with the following script. I need this script to listen to a particular UDP port continually. So it is set as a cron jon which will run every mits.

set_time_limit(60);
class pingtype
{
function rotate()
{

    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_bind($socket, '50.50.50.50', 9091);
    $from = '';
    $port = 0;
    $bytes_received = socket_recvfrom($socket, $buf, 150, MSG_PEEK, $from, $port);
    if ($bytes_received == -1)
    {
            die('An error occured while receiving from the socket');
            echo "Received $buf from $from\n";
    }

    echo "Received $buf from remote address $from and remote port $port";

    $hex_string_buf = "HEX: ".$this->strToHex($buf)."  String: ".$buf;

    $link = mysql_connect("localhost", "user_database", "123") or die ("Errror in connection ".mysql_error());
    mysql_select_db("database") or die ("Error in select ".mysql_error());

    $sql = "INSERT INTO socket SET contents='".$hex_string_buf."' ";
    mysql_query($sql) or die ("Error in query ".mysql_error());
    mysql_close($link);
    // close socket and delete own .sock file
    socket_close($socket);      
    usleep(1000);       
}
function strToHex($string)
{
    $hex='';
    for ($i=0; $i < strlen($string); $i++)
    {
        $hex .= str_pad(dechex(ord($string[$i])), 3);
    }
    return $hex;
}

function hexToStr($hex)
{
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2)
    {
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
}
}



for($i=1;$i<=6000;$i++)
{
    $object_pingtype = new pingtype();  
    $object_pingtype->rotate();
}
  • 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-06-11T08:30:03+00:00Added an answer on June 11, 2026 at 8:30 am

    You are overloading your server. If the script runs every minute, then this code is executed:

    for($i=1;$i<=6000;$i++)
    {
        $object_pingtype = new pingtype();  
        $object_pingtype->rotate();
    }
    

    This boils down to 6000 / 60 ~ 100 requests per second. If the server has not enough capacaty it will not finish this script in 60 seconds. And then a new script is started etc. etc.

    In the end of the day, your server will breakdown of al the tasks.

    Either:

    • Decrease the number of rotate’s in the loop
    • Decrease the times a script run’s per hour.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to fix the following, could please help me? $return .= <a href='<?php
I am wondering if someone could please help me convert a piece of PHP
Could you please help me out to find the correct deceleration rate for the
Could you please help me converting this c++ code into python: I am trying
Could someone please help me to convert this String into a Map ... String
Could you please help me to get image upload working on a view with
Could you please help me how to format a struct timeval instance to human
Could someone please help me in here, I'm just a beginner who want to
Could you please help me find out the time complexity of the Fleury' algorithm
Could somebody please help me get Clang up and running? (I don't have 3.2)

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.