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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:44:19+00:00 2026-05-27T10:44:19+00:00

How would I make my server run a php script by triggering it manually

  • 0

How would I make my server run a php script by triggering it manually using php? Basically I have a pretty big cronjob file that is ran every 2 hours, but I want to be able to trigger the file manually myself without having to wait for it to load (i want it to be done on the server’s side).

EDIT: I want to execute the file from a php file… Not command line.

  • 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-27T10:44:19+00:00Added an answer on May 27, 2026 at 10:44 am

    You can invoke a PHP script manually from the command line

    hello.php
    <?php
     echo 'hello world!';
    ?>
    
    Command line:
    php hello.php
    
    Output:
    hello world!
    

    See the documentation: http://php.net/manual/en/features.commandline.php


    EDIT OP edited the question to add a critical detail: the script is to be executed by another script.

    There are a couple of approaches. First and easiest, you could simply include the file. When you include a file, the code within is "executed" (actually, interpreted). Any code that is not within a function or class body will be processed immediately. Take a look at the documentation for include (docs) and/or require (docs) (note: include_once and require_once are related, but different in an important way. Check out the documents to understand the difference) Your code would look like this:

     include('hello.php');
     /* output
     hello world!
     */
    

    Second and slightly more complex is to use shell_exec (docs). With shell_exec, you will call the php binary and pass the desired script as the argument. Your code would look like this:

    $output = shell_exec('php hello.php');
    echo "<pre>$output</pre>";
    /* output
    hello world!
    */
    

    Finally, and most complex, you could use the CURL library to call the file as though it were requested via a browser. Check out the CURL library documentation here: https://www.php.net/manual/en/ref.curl.php

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.myDomain.com/hello.php");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true)
    
    $output = curl_exec($ch);
    curl_close($ch);
    echo "<pre>$output</pre>";
    /* output
    hello world!
    */
    

    Documentation for functions used

    • Command line: http://php.net/manual/en/features.commandline.php
    • include: https://www.php.net/manual/en/function.include.php
    • require: https://www.php.net/manual/en/function.require.php
    • shell_exec: https://www.php.net/manual/en/function.shell-exec.php
    • curl_init: https://www.php.net/manual/en/function.curl-init.php
    • curl_setopt: https://www.php.net/manual/en/function.curl-setopt.php
    • curl_exec: https://www.php.net/manual/en/function.curl-exec.php
    • curl_close: https://www.php.net/manual/en/function.curl-close.php
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create website thumbnails (screenshots) using php. I have a dedicated server
I know there are many posts about using CRON to run a php file.
I would like to make an ajax call to a different server (same domain
I am running a mysql server. I would like to somehow make sure that
I edited the question so it would make more sense. I have a function
I have a C++ app and looking for a library that would make it
I have created a php script to import rss feed into the database. The
I have the following simple script to test the mkdir() function in PHP: <?php
My website currently divides and displays messages in a conversation using PHP. I would
I run queries using SQLCMD utility via PHP and I wanted to know if

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.