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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:37:48+00:00 2026-05-24T23:37:48+00:00

So I tried executing a script two different ways: 1) foreach($result_array as $arg){ exec(/usr/bin/php

  • 0

So I tried executing a script two different ways:

1)

foreach($result_array as $arg){  
    exec("/usr/bin/php pathToScript firstArg $arg", $array);                
    echo "peak usage: " . memory_get_peak_usage() . "\n\r";  
}

results:
peak usage: 5457324
peak usage: 7791212
PHP Fatal error: Allowed memory size of 33554432

2)

    foreach($result_array as $arg){
        curl_file_get_contents("website?query=$arg"); //just a cURL helper function
        echo "peak usage: " . memory_get_peak_usage() . "\n\r";
}

results:
peak usage: 5241708
peak usage: 5241708
peak usage: 5241708
peak usage: 5241708
peak usage: 5241708
peak usage: 5241708
… you get the idea

I must be mistaken about either the way exec() uses memory, or operates. It was my impression that when the program is forked, using exec(), that the calling script’s memory requirements wouldn’t be effected… However, this seems to not be the case.

Can anyone shed some light on what is going on here so I know what’s going on?

  • 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-24T23:37:49+00:00Added an answer on May 24, 2026 at 11:37 pm

    The CURL version isn’t saving the response (the output of curl_file_get_contents), but the exec version is by appending the contents to exec‘s second parameter of $array:

    https://www.php.net/manual/en/function.exec.php

    If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().

    What happens is every response gets appended to the same array, ballooning the memory usage of the program.

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

Sidebar

Related Questions

I've tried executing the following: #!C:\cygwin\bin\bash.exe ls ${WORKSPACE} But that doesn't find ls (even
Below is the command I tried executing, without success: exec('ln -s ' . PLUGIN_DIR
I have a bash-script (let's call it /usr/bin/bosh ) using the following she-bang line:
Here's the script. Tried executing by itself ... nada. Tried executing via task scheduler
I just tried to create my first plpgsql function. When executing the script, I
I am trying to write the entire output (errors included) of an executing script
I want to run a shell script in php, but this shell script takes
I am trying to secure my PHP Image upload script and the last hurdle
I have a strange problem. I have a jQuery document.ready function executing some script
I am calling two function one Java script and one Jquery function on click

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.