One of my project needs me to run a Python scripts that are present on VPS. Is it possible to run those scripts from web interface? There are web development platforms out there like Django. Can those can help me in this project?
Example:
I need to set a cronjob from web interface on Ubuntu VPS.
I want some specific task to happen at some specific time, so for that I need to set a cronjob.
Is it possible?
Or, can I directly launch that Python script from interface without setting a cronjob?
If both case are possible please suggest. It will be a great help.
Thanks
I am not sure to understand what you need here. I'll explain a couple of solutions, pick the one you need.
You can edit the cron table with python and django to start whatever you need to start at a specific time
You can create a python web interface that calls your python script
You can use any languages you want and find the equivalent of python subprocess that allows you to run scripts
Edit the cron table with any languages you want
Related
I'm just curious about how these websites now a days can create an android apk? i mean what logic is behind it? is it possible that you can compile a code in PHP or is there something else?
e.g. for websites that can generate android apps
http://www.appsgeyser.com/
http://ibuildapp.com/
So just as a student, its killing me to know what they do for it?
Thanks
Nowerdays with the gradle build system that is not too hard. You just need to execute on the commandline gradlew aR and some minutes later you have a brand new apk file.
shell_exec('./gradlew aR');
That should do it's job but keep in mind that this can take some minutes.
A better way would be to queue that job in a database and execute the creation with a cronjob. That would be more secure.
They invoke the Android build tools on automatically generated code to produce the APK.
In fact, they do exactly what you would do to produce an APK, except that some of the code and resources are pre-built (and the same for every application), and whereas you would use Eclipse or Android Studio to compile the code, they are using scripts to so the same thing that the IDE would do.
I have a php project I'm working on using PhpStorm. I have a python script which manipulates my css file in a certain way before uploading it to the server (it's irrelevant to the question, but if you're curious, mostly related to language support).
I'd love to be able to run it directly from phpstorm, but I'm unsure how to do it (I'm guessing it's possible but I couldn't find any reference to something of the sort, and I'm kinda new to this IDE). I know I can rewrite the script with php but I'd rather not (I'm still a pythonist at heart).
Anyone had to tackle something of the sort?
Thanks in advance!
p.s. I'm running Ubuntu if that matters.
Use File Watcher plugin for that (should be bundled since v7 by default) -- this way such script will be run on each of desired modified files on save automatically.
http://confluence.jetbrains.com/display/PhpStorm/File+Watchers+in+PhpStorm
Alternatively you can use External Tools functionality and invoke it manually when desired.
http://www.jetbrains.com/phpstorm/webhelp/external-tools.html
According to the help page you can run scripts in the "Before launch". IMHO you can configure an external tool to be your python script (change +x to make it executable...).
Alternatively, I think you could install the python plugin (I've never tried it).
I've been working on a CMS for a few years and I actually implemented a jquery-based console in the admin area, where you could do some handy things like enable/disable modules and so on.
I recently fiddled around with drupal and decided to install cygwin along with drush.
I tried googling around but figured this might be an unusual question: How does one go about creating a CLI for a php-based CMS? And exactly how does exactly drush worK? I mean, I know that it runs from the command line as a batch script in windows. But how does it interact with PHP and so on?
I do know some basic C# but this shouldn't be very hard once i figure out how this fits together. (php, sql, etc).
Any help is appreciated, thanks in advance :)
You can run a php cli from the terminal only when you have php compiled with cli support. Additional you need to specify an interpreter and pass the path to the script as argument. But you can also use a shebang #!/path/to/php. A better practise would be to use the env variable and not hardcode the path to php: #!/usr/bin/env php. Read here about it: http://tech.vg.no/2012/02/21/dont-hardcode-php-executable-path-in-shebang/.
Basically you can write a simple CLI shell with a infinite loop plus a 'exec()' or 'shell_exec()' PHP functions. you should get the user commands and send it to shell_exec() function for execute in a system shell and return the output of that to the user.
i.e:
while(TRUE){
if($input != 'exit')
$output=shell_exec($input);
else
break;
echo $output;
}
you can add other options and customize this simple loop.
you can call external programs with 'exec()' function.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Making a distribultable standalone program in PHP
I don't know how to explain my idea...let me explain it by example....
Typically, I can have an application on the client side, when I launch it, it runs, until I close the application. Many desktop application works like that, right? But an application on php server is different, it only start processing when the user make request.... ....
So, my question is, can I make the php program become something like the desktop application, when I start it, it launch, until I kill the program, (for example, when I launch the application, it keeps pinging the google.com, until I stop the application.), doesn't need the user make request to "active" the program... Thank you.
If you have regular stuff to do, it usually done by cron ( http://en.wikipedia.org/wiki/Cron ), which invokes your script to run on the server.
If you want to start it from a command line, and want to do stuff again-and-again, you can write a while loop like
while($end==1) { do(); sleep(100); }
If you want to do a desktop application (which runs on the client, rather than the server), you can use: PHP-GTK http://gtk.php.net/manual/en/tutorials.php
If yours not one of the cases, please clarify.
What you are describing sounds like a daemon process, not a standalone application.
This is possible in PHP, the functionality is included in PEAR's System_Daemon package.
See this tutorial: http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/
The question is very easy, I want to execute several php files every "N" minutes. For example:
every N minutes
{
execute(script1.php)
execute(script2.php)
execute(script3.php)
}
I know about crontab but i was trying to find another solution. Any suggestions? Thanks in advance.
Using a Cron job is the usual solution. Can you explain why you don't want to use CRON? I've also seen libraries that add cron-like features to your system. For example in the Java/Groovy/Grails world there's the Quartz library/plugin. A quick Google search yielded a PHP library called phpJobScheduler that seems similar to Quartz. I have never used phpJobScheduler so I can't vouch for it.
I'd be interested in why you don't want to use crontabs for this? Are you going to be the primary web operations person running this server or will you be relying on an existing sysop team? You may want to get their input since they are the ones who will be most impacted by what method you choose. I've found they tend to be fond of cron for simple scheduling.
On windows I used built-in proggie called Task Scheduler. As for linux, yes, cron jobs is your answer.
You could create a php script to loop forever do X every N minutes and run the command with a & to make it a background process.
/path/to/php /home/user/bgscript.php &
If you want it to always run, you'd then have to add it to startup init.d or services depending on flavor of *nix.
This solution is possible but personally I would highly recommend going with crontab, its established, proven and works well! Why are you avoiding it?
You could build a script and let it run as a daemon and perform certain tasks on a set interval, but that's actually just simulating cron ... and if you have the ability to run a php script as a daemon you should really also be able to run it as a cronjob since that's what crons are made for.
If you need more info on how to run a php script as a daemon read this great intro. There is also a great comparison between daemon and cron inthere, worth the read.