I'm trying to run the userOptions script for MediaWiki to add a new namespace to the default search namespaces for all existing users. Unfortunately, I don't have shell access to my hosting provider, and to be honest I'm really not at home with using cron jobs.
What's the easiest way for me to run this script on my MediaWiki install:
http://www.mediawiki.org/wiki/Manual:$wgNamespacesToBeSearchedDefault#Changing_options_for_existing_users
(sorry, the url won't parse properly)
For instance, is there a php command that can do this?
Create your own PHP script. In it, populate the $argv and $argc variables, and then just include the userOptions.php file in your own PHP file.
Related
I wrote a simple project boostraper using bash.
It asks simple questions such as the parent folder to create the project inside, the type of the project (cli, web php, web symfony, web npm, etc…), the required dependencies, bootstrap everything, init git, and so on.
Then it returns the terminal to the user after changing the working directory to the freshly bootstraped one.
Fine.
I decided to rewrite the whole script using php in order to have a more user friendly cli interface (nice menus, progress bars, etc…) and to be able to pack the whole script in one and only binary (phar).
I struggle with the last part of the script: The one which was the simpliest part of the previous bash script:
cd $newprojectpath
exit 0;
For a reason I can't really figure out, I cannot do the same using a php script.
chdir allows me to change the working directory for the current php process but as soon as it is over, I'm back to working directory from where I invoked the php script (the one from where I spawned the php interpreter sub-process, obviously).
The only way I found in order to achieve this very simple move is to spawn a new shell sub-process from the php script itself.
It works, but I don't like it.
chdir($project->path);
pcntl_exec(getenv('SHELL'));
Did I miss a more simple way to change working directory using PHP cli ?
I am trying to run a cron-job that automates the cache rebuild function of Woo Search Box plugin.
The plugin has this dynamic cron command, that I set to run once a day at 1AM:
php /home/carit/public_html/index.php 16021417635f7ebe43c604a
I am well experienced with cron jobs inside of C-Panel but I can't figure out what prevents this cron from running. All in all, I have tried what the documentation suggests here, also tried usr/bin/php instead of php but it didn't make any difference.
If I run this cron-job inside my server's terminal, it works like a charm and the cache is being rebuilt. It only seems to not be working when I run it via cron-job.
Does anyone have any suggestions or ideas on why doesn't this cron-job works?
Please correct me in the comments in case I forgot to provide any key information about my problem,
Thanks.
It seems that some newer versions of CentOs or Ubuntu servers use either /usr/local/bin/php or simply /usr/bin/php. If you have ftp access to the server you want the cron to run in, make sure to check for the php file in both paths recommended above before trying to use the ordinary php before a cron job.
i'm making an extension that use a php file in the 'public' directory as a webhook.
From this hook, I will need to run some shell commands (things like npm run build or similar). Is there some kind of api from plesk that let me do this? Or should I use a php function like exec or shell_exec?
I looked through the net, but in the end it looks like what I'm trying to accomplish is not doable. You can indeed use shell_exec to run shell commands, but the user used to run this commands is psaadm, which is a severely restricted user when operating inside a domain document folder. You can see the files, but not create or execute any script, which renders this function useless for what I wanted to do.
If you want to use a webhook tu run your npm build (or other scripts), you can always create a php file in the document root folder and execute your commands using shell_exec. When you call this file, it will execute the commands as the customer user, and will have the ability to run those scripts.
P.S. It might actually be accomplished if you change the permission for the psaadm user, but it's not something a customer which install an extension should do. Still, not sure if it will work for the domain document root folder of your customers.
I am testing an application in MAMP and would like to add a cron job, or as I am on a mac the job through is run through launchctl. My cron is a php file that runs a database query. Naturally the php file and mysql db are in separate directories. Where should I change my working directory to such that the cron will query the database? FYI, I have a standard installation /Applications/MAMP/...
Many thanks.
My mistake above was that I was trying to point to the database's directory, when the php file had already handled that for me. Running the program was as simple as running the following code:
php -q /path/to/my/doc.php
I found it was easiest to manage launchtl through a $5-$10 program called lingon. Highly recommended if you are considering managing multiple crons at a time. Otherwise, if you want to stick to the command line, this is a good tutorial.
I have a php file that calls exec() on a c++ exe.When the .exe is finishing running I need to run the php file again,repeat .
I am wondering what is the best way to do this? This .php file has no user interaction and needs to be completely automated.
EDIT:Found another solution that would kill the process if it is already running which will cover this issue well.See posts on this page.
http://php.net/manual/en/function.getmypid.php
Here's a simple Linux line that starts up the script in the background and uses the watch command to restart the script whenever it finishes running:
watch -n 0 php /path/to/script.php &
Once you've started it like this, you can use the ps command to list running processes and find the process ID for watch, and then use kill process_id to stop watch.
It's probably not best practice to run commands like this, but it's a quick and easy solution that doesn't require any special access privileges on the system (whereas using cron might), and doesn't involve editing your code (whereas a codeigniter solution will).
I haven't used codeigniter before but there seems to be a solution as described in the wiki.
Depending on how you can access the system (if you are admin or not) and depending on how you are planning to update the automated commands, IMHO, you could use both solution (Linux crontab or codeigniter cron script).