Consistency around the .phar extension in PHP - php

Kind of simple question, but I'm new to php and have spent too much time trying to google a simple question. I'm using php 5.6 and many guides (codeception, for example) talk about running a command like php vendor/bin/codecept.phar. My files often don't have the extension and i don't need to use php to execute them. Is this just something that evolved out of the language and is now optional?

A .phar file is a compressed archive containing one or more PHP files:
The phar extension provides a way to put entire PHP applications into a single file called a "phar" (PHP Archive) for easy distribution and installation.
Source: http://php.net/manual/en/book.phar.php
There is no requirement to run it from the command line with php, just as there is no requirement to run a .php script from the command line with php. As long as the file is marked executable and has an appropriate shebang it can be run as a standalone file.

Related

PHP ImageMagick script not working when executed via command line

I have a PHP script I'm trying to execute via the command line using the exec() function and I'm getting errors saying PHP can't locate the various classes that are part of the PHP ImageMagick extension (PECL is what I'm using) but it is installed correctly and works fine when running other scripts that use it via the browser.
I'm executing my code this way to create multiple instances and essentially cause parallel processing by allowing Linux to optimize the various processes across my CPU cores on its own. It works great for all the other things I use it for, but not in this situation.
Do I need to change how I installed Imagemagick?
PECL Extension was missing from CLI INI File. Apparently there are two of those files, on for browser execution and another for command line interface.

How to portably include Windows' runtime library to binary PHP CLI

I'm working on small app which users can download and which includes a php file and binary version of interpreator PHP for Windows (PHP CLI). All is packed in one .zip folder and as we know to start build-in PHP server it's enough to unzip the folder on any hard disk, add the path to binaries to the PATH variable and then in the command line go to the folder and execute
php -S localhost:80
But as we also know to make PHP working on Windows, we need also respective runtime library. For example for the latest PHP 7.3 we need VC CRT 14 (Visual Studio 2015). I would like to pack it also in my zip, but as "portable" i.e. without a need to run an installator and if possible even without copying to C:/Windows/System32 I mean we just unpack only one zip folder on any disk, run the cmd-command and everything to be working without additional actions.
On the page http://php.net/manual/en/install.windows.requirements.php I read that it's possible to gather all installed DLL files. How can I do that? Maybe there is ready-made list of the files? (I'm primarly interesting in VC 14 for PHP 7.3, but it may be also VC 11 for PHP 5.6)
Is it possible then to include the library to binary PHP CLI without installation the library and even without copying its files to the System32 folder?
Have someone an experience in something like that?
Oh, it turns out that it's enough only to download vcruntime140.dll from Internet and put the file in the PHP 7.3 folder to make PHP CLI working on Windows. No need to install something or even copy to the Windows/System32 folder.

Run a C++ Application on a Webserver with WordPress

I have a C++-library (.so) for some calculations that I would like to call from Wordpress/PHP via an input formular. The promising idea to build the .so-library as a PHP extension using PHP-CPP has been fine locally on Ubuntu 14.04. But on the webserver this method failed because my webhoster doesn't support changing the extension directive in the php.ini/.user.ini. I see the following alternatives:
Build an exutable application and run it from PHP via proc_open() and send a lot of variables to the stdin of the application. Wordpress itself offers PHP plugins.
Redirect to another server where my own php extensions are supported.
Is there a way using python/web2py for that purpose?
Which would be best?
Or any other ideas?
Probably the simplest way is to create command line utility in C++ and execute it from php with shell_exec. I tried that in past and the performance was not too bad.
"Probably the simplest way is to create command line utility in C++ and execute it from php with shell_exec. I tried that in past and the performance was not too bad."
This did help. Finally I managed a build on Linux which was portable to the webserver where the website and wordpress are located. The call to the binary built from C++ was done with shell exec or popen in PHP (which one I don't remember, it was in 2018). The PHP code was finally migrated to an own wordpress plugin. Unforunately, I could not use PHP-CPP due to missing admin rights for the webderver. But the integration via shell exec or popen works fine.

How to create a shortcut in php?

Is it possible to create a shortcut that points to in-existing file in php and make it run normally in windows?
Example
makeshortcut("C:\Windows\calc.exe","short.lnk");
Then when I download the shortcut, it would open calc on my computer.
I don't have COM enabled, I do have exec() enabled, so I can run some kind of perl or python, however, lots of extensions are disabled, particlarly (pywin32 and win32::shortcut), so it would be highly appreciated if I can do this only in php or using calling another script with exec() which doesn't require me to install additional extensions.
The linux ln command has nothing to do with Windows .lnk files, and they are not compatible.
Here is some info on the .lnk file format.
As you can see it is not trivial to create from scratch.
liblnk library allows you to read .lnk files in Linux, but I haven't seen one that allows for their creation.
Edit:
Here is a SO question similar to yours:
Generate Windows .lnk file with PHP and Creating a Desktop Shortcut Using a Web Page
You can use http://www.mamachine.org/mslink/index.en.html - a bash and c program to create a shortcut.
Compile the C program for your platform and call it with the shell_exec function.
Even if the question is old, I hope it helps others.

How can I create a PHP extension on Windows?

More specifically, I'm trying to make a PHP extension for WampServer, which I'm using to test PHP scripts on my PC. I know that a PHP extension requires a config.m4 file, and some C/C++ code to be created within PHP. How would I get these .c/.cpp and .m4 files into a .dll that's required to make a PHP extension?
Take a look at this : Getting Started with PHP Extension-Development
Generally you need C compiler (with or without IDE), I recommend MS Visual C++ Express.
Then follow this tutorial: http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/

Categories