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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:14:37+00:00 2026-06-10T23:14:37+00:00

I have a php script that runs for about 2 hours. It is a

  • 0

I have a php script that runs for about 2 hours. It is a cron job. The cron job runs every 4 hours.

At the end of the script, I display some memory values.

The memory_get_usage() result is 881568 Bytes (0.840766906738M)
The memory_get_peak_usage() result is 1340304 Bytes (1.27821350098M)
The memory_get_usage(true) result is 1572864 Bytes (1.5M)
The memory_get_peak_usage(true) result is 1835008 Bytes (1.75M)

The memory_limit in php.ini was 128M and it didn’t work. I raise it to 256M and now it works.

But as the memory peak of the script is less than 2M….

So how does the memory_limit parameter work?

Is it the total memory used by the script? If so, how can I calculate it?

Is it the memory peak of the script? if so, am I calculating it right?

I’m using php 5.3.16.

EDIT

I don’t have any error messages. When the limit was 128M The script executes, but never finishes.

  • 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-10T23:14:38+00:00Added an answer on June 10, 2026 at 11:14 pm

    Try using a function that uses your operating system to report actual memory such as this one.

    function unix_get_usage() { 
          $pid = getmypid(); 
          exec("ps -o rss -p $pid", $output); 
          return $output[1] *1024; 
     }
    
    function windows_get_usage(){
        $output = array();
        exec('tasklist /FI "PID eq '.getmypid().'" /FO LIST', $output );
        return preg_replace( '/[^0-9]/', '', $output[5] ) * 1024;
    }
    

    Your script probably consumes a lot of memory that PHP doesn’t consider when returning from memory_get_usage() (which looks at the heap btw). Stack allocated variables would have been cleared up by the time memory_get_usage() was called and returned.

    You should also try running this function and others at other points during execution, e.g. after big MySQL calls or file processing. memory_get_peak_usage() may not work on all OS’s, especially depending on compile options.

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

Sidebar

Related Questions

I have a php script that runs a mysql query, then loops the result,
I have a command-line PHP script that runs a wget request using each member
I have a php script that is run once a minute. The script runs
I have a PHP script that runs a SELECT query then immediately deletes the
I have a PHP script that runs once a day, and it takes a
I have a PHP script that runs database queries. Now, if a query fails,
Ok, so I have this PHP script that runs in a nice little infinite
here's a weird one: I have a PHP-CLI script that runs just fine when
I have a scheduled task that runs a script on a regular basis (every
I have an image uploader that runs on a separate PHP script, and then

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.