run python script from phpstorm - php

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).

Related

How to write a PHP extension to work with the console program?

There is a console program for morphological analysis of text https://tech.yandex.ru/mystem/.
Work with the program from the console is simple:
./mystem -lwd in.txt out.txt
I need to carry out a morphological analysis of the text by means of PHP, use the exec () function is impossible.
The easiest way, using PHP to write text to a file, then using a bash script and cron to analyze and save into another file.
But I would like a more convenient option as a PHP function mystem (string, param).
Compile and install extensions I can, but do not know how to write them.
I think the problem is very simple, because maybe someone is faced with the decision of this problem is the "fish"?
Total my question is, Does anyone have a ready solution where you can change only the name of the console program and the expansion will be ready? Thank U!

Executing ANT from PHP

I have an HTML form which I am submitting to a PHP script. I am using PHP to write an XML file based on the form input, and then I would like to have PHP execute an ANT buildfile that will use the XML as input for an XSLT task. All of this is part of a much larger application, none of which is exposed beyond our LAN, so security is not a huge concern of mine. My problem is that I cannot get the PHP exec task to start ANT. I have tried seemingly every combination of executing a BAT that calls ANT, using the full path to the ANT binary, calling ANT with java, etc. All roads lead to:
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
I am running PHP 5.3 on Windows Server 2008 running IIS7. The PHP is located in inetpub/wwwroot/etc. Ant is installed in C:\Program Files. I personally don't believe it's a permissions issue, but I could be wrong. I have scoured the web in search of the answer, but I have only found the question unanswered or suggestions similar to those mentioned below.
I am currently attempting to install phing, and will consider another server-side scripting language to accomplish the same job (I am just way more comfortable in PHP). But if anyone knows of the issue and how I can work around it that would be awesome.
Cheers!

Writing a CLI for a php-based CMS (Similar to Drush)

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.

build PHP with ant scripts

I was just wondering how I use Ant to build my web applications that I have written in PHP? I've googled around a bit and I have seen that it is possible but there are not any examples of the basic idea or any advanced use for them. Can any of you help me out?
Thanks!
This is definitely possible. If you are looking for a pure php solution phing might be what you want. Also note that there's usually no reasons to build PHP scripts. They should 'just work'.
While Ant itself is written in java, you can use it to build any kind of applications you want. Here's a basic tutorial and a full manual. Beyond that, you need to clarify what is it you want to do to get a more precise answer here.
Update (based on question clarifications):
Copying / moving files / folders is easy via Ant. Look through the "Hello World" tutorial I've linked above and Familiarize yourself with FileSet concept and Copy, Mkdir and Move tasks to get started. Here's another tutorial that shows how to set up a basic build (ignore java-specific stuff like javac/war).
Making changes to the database is an entirely different subject. If you have 'alter' scripts ready, you can use Ant's Exec task to invoke your DB's command-line client to run those scripts (though I probably wouldn't do it in production). If you want to use Ant to track those changes, then you're looking at the wrong tool. Liquibase can be used to do that and it seems to be getting a lot of traction lately. It's quite like Ant in the sense that it's written in Java but can be used in any environment. I'm no PHP expert so I wouldn't know if there's something more PHP-geared available.
We use ant to 'build' php apps. At it's most basic, the ant script just copies the file into the folder on the testing webserver (localhost in my case).
Why do this? well there's not a great deal of point to it, but it is a handy way to avoid putting .svn files into the webserver. If you want to change the location of the webserver you can just build to the new location. You can also do different things according to whether you're on Linux or Windows for example, but I've never used that side of it.
Having tried Phing, Ant and Gradle, I would strongly recommend gradle. Here is a bit of description Choosing tools for PHP application automation

PHP as a Desktop Programming Language

I'm not much of a programmer, PHP is where I'm comfortable. And sometimes I find that I need to do things, such as arrange files or rename files on a mass scale on my computer. And I think I could do this with PHP but I can't of course.
So I was curious, is there a way I could run PHP files as kind of exe files.
EDIT: Fairly important point, using Windows.
just use php.exe (put it in your path) and the name of the php file you want to execute
You should have a look at php gtk
It's not as bad as you put it. PHP may be a very good tool for string related stuff like parsing, renaming etc. Especially if you know PHP.
To use php as script you should add #!/path/to/php as first line and set execution permissions on unixoid systems. In windows you can simply assign the php file ending with your php cli exe so you can click on them or use the script with the "start" command in the windows shell. But make sure that you write your scripts in a way that it is sensible to the current working directory. It may be different to what you might expect sometimes.
to be able to execute php files with double click, just like normal programs, go to the command line, then type
ftype php_script "C:\path\to\php.exe" "%1"
assoc .php=php_script
Check out WinBinder
Sure, just add #!/path/to/php to the top of the file, add the code in tags, and run it as a shell script.
Works fine - the php binary you use is either the cgi one or the purpose built CLI version.
http://www.php-cli.com/
http://php.net/manual/en/features.commandline.php
it would appear so, yes.
Download Wamp Server, install it. Once thats done, add the path to the php.exe to your PATH settings. You can do this by going to control panel->system->change settings->advanced->environment variables. Edit the PATH, add a ';' to the end of the line and then past the path to the php.exe. This is on Vista, it might be different on XP or Windows 7.
My path looks like this after: C:\Sun\SDK\jdk\bin;C:\wamp\bin\php\php5.3.0
Once thats done, you'll be able to execute a php file from the command line. You could create shortcuts too.
C:\Users\Garth Michel>php test.php
This is a test
C:\Users\Garth Michel>
I used php for years as a scripting language before I even bothered to use it as a web programming language.
maybe php is not the right tool to doing this and it's about time to learn another language...use this chance to expand your programming horizion
See the .reg file in this gist, it makes it possible to use .php files exactly like .bat files, e.g. my_script.php foo bar baz
Don't forget to edit paths to suit your setup.
http://www.appcelerator.com/products/download/ Still use html & css as a desktop app and now has support for php.
PHP based web apps like Wordpress and Mediawiki I think uses php to setup and configure itself. Just give IIS proper read/write rights and you can make a simple web app that does massive renaming, etc.. PHP doesn't have to always be used for writing out html.
See ExeOutput for PHP. It has excellent customization and MAGNIFICENT features. Yet it is not an IDE or something. It compiles your PHP+HTML into fully-fledged EXEs.

Categories