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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:51:04+00:00 2026-06-02T06:51:04+00:00

Is there a correct way to use php from the command line…or rather…is one

  • 0

Is there a correct way to use php from the command line…or rather…is one way more correct than another ?

If you create a file, say test.php with the following code:

#!/usr/bin/php
<?php
print "This is a test".PHP_EOL;
print "This is another test!!";
?>

then chmod +x text.php (make it executable on linux).

You can then run in the following ways…..
./test.php
or
php test.php

I prefer just using ./test.php, but often see php test.php in examples.

ALSO

is the following correct syntax for the shebang line
#!/usr/bin/php
or is this more correct
#!/usr/bin/php -q

I’ve seen both, and see that the -q flag is to quiet the html stuff, but was wondering if
php compiled with cli compatibility really needs the -q flag ???
Thanks for your help 🙂

  • 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-02T06:51:05+00:00Added an answer on June 2, 2026 at 6:51 am
    #!/usr/bin/php
    

    On the first line of an interpreter script, the “#!”, is the name of a program which should be used to interpret the contents of the file. For instance, if the first line contains

    “#! /bin/sh”

    , then the contents of the file are executed as a shell script.

    In your case it means excute the script using the php file in /usr/bin location.

    Using php test.php means that you are running your test.php with php so u don’t need the first line. where as for ./test.php your file needs to be executable and first line is required.

    And about the -q flag look at this
    specifically on

    rob 23-Mar-2007 11:48

    There are better expanations if you see for -q. here’s another one

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

Sidebar

Related Questions

I'm learning how to use the command line by requirement for a recent project.
update: I know there is no one best way to do everything. Sorry for
Firstly I know that there are many question and solutions to correct thread marshalling
What do you think? Is this correct or are there memory leaks? Source: #include
There seem to be very different opinions about using transactions for reading from a
There are many conflicting statements around. What is the best way to get the
There exists an RSS feed with over 1000 items. I want to create a
Is there a way to connect my flex web application to Active Directory, and
I am writing a PHP application targeted at non-geeks, non-programmers. I need to create
I would like to call a cron job from within a PHP script. I

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.