Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I've got a simple script that sends email if you refresh the page. I need it to run every week. I setup a command in CPanel to run that script
php /home/site/public_html/test/sendmail.php
But it does not work. Hosting support says I setup cron in CP correctly.
I wander if I need any intermediate script to run sendmail.php. Thank you for your help in advance.
Most likely you'll need to expand your cron call to /usr/bin/php /home/site/public_html/test/sendmail.php, because the system can't find the path to the php executable.
You can also add a PHP shebang to the script and run it like a normal shell script without php -f:
#!/usr/bin/php
<?php
//your code
?>
To get the PHP path, use this code: <?php echo PHP_BINDIR, PHP_EOL; ?>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to set up my system so that php can be run without including the shebang in every file. Is there an alternative to using #!/usr/bin/php in every php file I write?
The shebang is only needed, if a PHP should be called directly by a shell/tool like any other shell script. Examples are functions system() or exec*() provided by many languages, including PHP.
If calling a command, the tools look for a shebang to decide, which interpreter is to call. This works for awk too:
#!/usr/bin/awk -f
BEGIN { print "begin" }
The general idea is, to put commands e.g. in /usr/local/bin, make chmod a+x and use them like any other command without need, to select the needed interpreter manually.
Conclusion
Shebang is not needed for web server files, that are never called as script by a shell or external tool.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have php file on my linux hosting server and i want to execute it 2 times a day. Below is my link of my php file. Kindly tell me command line code for my php file.
http://viewpackages.com/prices/generator/footer.php
See attached image which is my hosting cron job form. Tell me what i have to write in command line text field
click here to see image of my hosting cron job form
Try pasting this on the command option:
wget -O /dev/null http://viewpackages.com/prices/generator/footer.php
Test it and tell me if there's anything wrong
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a php script which runs using terminal and then it keeps running. It dumps data from a remote server into local directory by creating .txt files. Now I want to create a Mac app which once open will run this script.
I dont want to use terminal I just want to create an app which when starts runs the script and as long as the app is running the script would be running.
My question is is there any way we can run a php script in a Mac application.
Create a YOURNAME.command file, put what you want to execute inside and make it executable with chmod +x YOURNAME.command
The file when you double click will execute what you put inside.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have uploaded a php base project to domain , which send messages from webpage to mobiles.For this purpose user open webpage every midnight and the code work well.
My question is can i update my script to send message automatically at midnight without a user open that page in browser?
i searched and find a result of cron-job. if it is right that with cron-job a domain send messages without any laptop or computer browser than please give me scripts of how to use cron-job in php. because i am totally new to cron-job.
otherwise please suggest me a way of doing such job. thanks
I would use the crontab feature inside a linux server
crontab -e
and then enter it like this:
wget -O /dev/null "{URL_GOES_HERE}" > /dev/null 2>&1
Of course change the {URL_GOES_HERE} to the real url. This will run every minute, if you want to run per 5 min or equal then you can checkout the link on wikipedia.
https://en.wikipedia.org/wiki/Cron
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want my web server to run a .sh script that runs a series of .jar files. I want this to happen as soon as the server is contacted without any input from the user. A PHP or JS script would be preferable. Is it even possible to do this?
Thanks in advance
You can also look at gearman.org. It is safer and more flexible than shell_exec().
It is not doable in JavaScript, but you can use PHP for it. If I understand your question well, you have some utilities written in Java and you don't care about their output. The shell script would look like as follows:
#!/bin/bash
java -jar your-jar1.jar
java -jar your-jar2.jar
...
and provided the name of the script is myScript.sh and it has the x flag set, you can run it from PHP by:
shell_exec('path-to-script/myScript.sh');
<?php
exec ("sh your_script.sh");
?>
place this in your webserver root as a php file and replace your_script.sh with the name of your script.
WARNING: if you don't protect the script with a password, using for example a .htaccess file for Apache (http://httpd.apache.org/docs/current/howto/htaccess.html), anyone can execute that script.