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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:07:05+00:00 2026-06-10T09:07:05+00:00

I am forking php code, kicking off scripts to run in the background allowing

  • 0

I am “forking” php code, kicking off scripts to run in the background allowing the browser application to continue without having to wait for a response.

I would like to be able to pass a parameter to such a script.

Say i have an array i would like to be accessible to the script in question, how could i pass it over?

$test = array(1,2,3);

//for windows i do the following which works well enough 
pclose(popen("start php /path/to/script.php ","r"));

OR for some linux distro’s :

exec('php -f /path/to/script.php >/dev/null 2>&1 &');

so firstly, is it possible to pass my array to that script? if its possible to make it accessible to the script, how could i access the passed variable in that script?

(sitting here confused, thinking about passing variable by value/reference….)

thanks!

  • 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-10T09:07:06+00:00Added an answer on June 10, 2026 at 9:07 am

    Nicolas Brown is almost right. But that would be the second part of the solution you’re looking for, I think.
    As you maybe already know you can call a program from the console and yet pass any arguments the program might expect:

    >php -f /path/to/program arg1[ arg2 ... argN] >/dev/null 2>&1 &
    

    So as you’re passing a string to exec() why not just “insert” your array as arguments and then execute it

    $test = array(1,2,3);
    $args = implode($test, " ");
    $prog = 'php -f /path/to/script.php ' . $args . ' >/dev/null 2>&1 &'
    exec($prog);
    

    Here comes something from the tutorial Nicolas Brown mentioned. In your script.php you can get the parameters from $argv[]

    $myParam1 = $argv[1];
    $myParam2 = $argv[2];
    

    Please, note that in argv[0] is the name of the program. That’s exactly why in the tutorial they first do arry_shift($argv), to get rid off the first element (the program’s name and path).
    Hope it helps!

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

Sidebar

Related Questions

I'm interested in kicking off processes after a web request, or possibly forking a
I am forking some php scripts and I need to update a mysql row
I am now trying to do forking in php. I would like to do
does PHP support something like ampersand in bash (forking)? Let's say I wanted to
I'm dynamically filling a div with li elements using php. I was having trouble
I have an application in PHP that is a simplified MVC type structure. This
I have numerous index.php scripts using SEO-friendly arg format like example.com/path/to/index.php/opt/arg and would like
I have a number of command line scripts in PHP that use exec() to
I have this PHP code: $result = mysql_query(SELECT distinct om_quote_no from `porders` order by
I have a problem with forcing php to download a file, when i run

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.