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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:28:45+00:00 2026-05-24T21:28:45+00:00

I want to define a variable in php with in a global scope. That

  • 0

I want to define a variable in php with in a global scope. That variable should be accessible for each user, so it should not depend on the session.

I want to do something like the following: I have a php script, and that script usually takes about 5 to 15 minutes to execute, but it can take more than one hour in some special cases. This script is being run using a cron job with a 15 minutes interval. This script can also be run manually by any user.

Now it’s possible to run any number of scripts at the same time. I want to limit this number of scripts.

So, I want a variable to store the number of currently executing scripts. I don’t want to use a DB or files to store a single value.

Thanks in advance.

  • 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-24T21:28:46+00:00Added an answer on May 24, 2026 at 9:28 pm

    Writing the variables to a specific memory address and reading and writing to/from that address with information such as a count might work.

    An (old) article on IPC (inter process communication) might help you

    http://zez.org/article/articleview/46/

    Out of interest why is it you don’t want to use files or a database?

    Another solution (despite more than likely technically using files or a database) would be to force the script to use a specific session ID.

    <?php
    
    $maximum = 1;
    
    session_id(md5('myscript'));
    session_start();
    
    if( !isset( $_SESSION['count'] ) ) {
        $_SESSION['count'] = 1;
    } else {
        if( $_SESSION['count'] >= $maximum ) {
            die( "too many processes running" );
        } else {
            $_SESSION['count']++;
        }
    }
    
    session_write_close();
    
    // simulate running something
    sleep(10);
    
    session_id(md5('myscript'));
    session_start();
    
    $_SESSION['count']--;
    
    session_write_close();
    
    echo "<br />executed";
    
    ?>
    

    Note in the example above, the call to session_write_close() is important because the execution of the script will prevent the counter being incremented until it finishes otherwise. And then as it closes it, it needs reopening to decrement the counter.

    Obviously because of the session reopening, any output from the script would need to be buffered (see http://www.php.net/ob_start) to prevent headers already sent errors

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

Sidebar

Related Questions

I want to define something like this in php : $EL = \n<br />\n;
I want to define global array constant code in bootstrap.php $adv_types = array('top' =>
How can I define a global javascript variable in this situation? I want the
I want to define some member variable and some code just in Debug Mode,
I use the same constant in all my php files. I do not want
I want to do define the following variable $url $url = www.example.com/$link; where $link
i have to define a variable that i am using in a program but
Say I've got a global variable which I'm accessing inside a PHP block, which
I want to pass the variable from php page to another without using sessions.
I want to define a JavaScript class, Foo. Foo = function(value){ this.value = value;

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.