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.
You can invoke a PHP script manually from the command line
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/orrequire(docs) (note:include_onceandrequire_onceare related, but different in an important way. Check out the documents to understand the difference) Your code would look like this:Second and slightly more complex is to use
shell_exec(docs). Withshell_exec, you will call the php binary and pass the desired script as the argument. Your code would look like this: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
Documentation for functions used
include: https://www.php.net/manual/en/function.include.phprequire: https://www.php.net/manual/en/function.require.phpshell_exec: https://www.php.net/manual/en/function.shell-exec.phpcurl_init: https://www.php.net/manual/en/function.curl-init.phpcurl_setopt: https://www.php.net/manual/en/function.curl-setopt.phpcurl_exec: https://www.php.net/manual/en/function.curl-exec.phpcurl_close: https://www.php.net/manual/en/function.curl-close.php