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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:02:01+00:00 2026-05-26T08:02:01+00:00

my question is probably easy to answer. i want to execute my php file

  • 0

my question is probably easy to answer. i want to execute my php file with shell and pass parameters to it via shell
example

php test.php parameter1 parameter2

is there a way to do that except using GET ?

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-05-26T08:02:01+00:00Added an answer on May 26, 2026 at 8:02 am

    Yes you can do it like that but you should reference the arguments from the $_SERVER['argv'] array. $_SERVER['argc'] will tell you how many args were received, should you want to use that as a first layer of validation to make sure a required number of args were input.

    To illustrate this, running the following script as args.php arg1 arg2 arg3:

    #!/usr/bin/php
    <?php
    var_dump($argv);
    ?>
    

    will output:

    array(4) {
      [0]=>
      string(8) "args.php"
      [1]=>
      string(4) "arg1"
      [2]=>
      string(4) "arg2"
      [3]=>
      string(4) "arg3"
    }
    

    Here is a practical example:

    In this example, we’ll create a script (days.php) that outputs the number of days since a particular date. It will accept 3 parameters, the month, day, and year as numbers.

    #!/usr/bin/php
    <?php
    if($argc < 4 || !is_numeric($argv[1]) || !is_numeric($argv[2]) || !is_numeric($argv[3]))
    {
        echo "Usage: $argv[0] mm dd yyyy\n";
    }
    else
    {
        $pastdate = mktime(0, 0, 0, $argv[1], $argv[2], $argv[3]);
        $diff = time() - $pastdate;
        $days = round($diff/60/60/24);
        echo "$days days since $argv[1]/$argv[2]/$argv[3]\n";
    }
    ?>
    

    Shell call:

    `$ ./days 11 17 1988` OR `php days.php 11 17 1988`
    

    Output:

    7699 days since 11/17/1988
    

    Hope this helps.

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

Sidebar

Related Questions

This is probably an easy question, but I want to understand better how Apache
simple question, probably easy for you to answer. I have a dll named MigrationSteps.dll
Hopefully this question has an easy answer. It's probably something stupid I'm doing! In
This is probably a very easy question to answer, but for the life of
I'm rubbish at Linux, so this is probably an easy question... I want the
This is probably a really easy question to answer, but for some reason I'm
Probably an easy-to-answer question. I have this procedure: CREATE PROCEDURE [dbo].[AccountExists] @UserName nvarchar(16) AS
This is probably an easy question to answer, but I don't see it mentioned
This is probably a question that has an easy/simple/obvious answer, but I've found myself
So this is probably a fairly easy question to answer but here goes anyway.

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.