I've created tool, that runs as a server, and allow clients to connect to it through TCP, and run some commands. It's written on python 3
Now I'm going to build package and upload it to Pypi, and have conceptual problem.
This tool have python client library inside, so, after installation of the package, it'll be possible to just import library into python script, and use for connection to the daemon without dealing with raw TCP/IP.
Also, I have PHP library, for connection to me server, and the problem is - I don't know how to include it into my python package the right way.
Variants, that I found and can't choose the right one:
Just include library.php file into package, and after running "pip install my_package", I would write "require('/usr/lib/python3/dist-packages/my_package/library.php')" into my php file. This way allows to distribute library with the server, and update it synchronously, but add long ugly paths to php require instruction.
As library.php in placed on github repository, I could just publish it's url in the docs, and it'll be possible to just clone repository. It makes possible to clone repo, and update library by git pull.
Create separate package with my library.php, upload it into packagist, and use composer to download it when it's needed. Good for all composer users, and allow manual update, but doens't update with server's package.
Maybe I've missed some other variants.
I want to know what would be true python'ic and php'ic way to do this. Thanks.
I've decided to create separate PHP package for my PHP library, and upload it to a packagist.org, so, user could get it using php composer, but not forced to, as it would be in case of including library.php into python package.
Related
I'm trying to use the Plivo PHP helper library in my project, but looks like the only way to use it is with Composer. Is there any work around for this since I cannot use composer in my project as it would change the existing code?
Plivo Sales Engineer here.
Unfortunately, Plivo-PHP helper library can be used only with Composer. If installing the library with Composer is not feasible, you could download and install the dependencies individually and include the libraries in your project. Or, you could also make HTTP requests to the API directly without using the helper library. You could use cURL or Requests library to make these requests.
I had a similar issue.
The access to the server was very limited, I had only FTP access, I could have waited to ask for SSH access to do the install using composer I simply installed Composer on my local machine and then just had to run
composer require plivo/php-sdk
In an empty directory. It created the SDK files under /vendor and I uploaded those files through FTP to the server. Did the job for me.
I have a laravel app and i want to use the pagseguro/php package.
I added it to the composer.json and updated. I can access the main class (PagSeguroPaymentRequest) without a problem.
At some point I have to call this:
PagSeguroConfig::getAccountCredentials();
But it throws an exception. After reading code around I thought on trying to init the library by myself and suddenly everything worked:
PagSeguroLibrary::init();
This method is inside the only php file in source/PagSeguroLibrary/
Shouldn't composer automatically execute this method? What is exactly "loading" a package? Is there anyway to fix this using composer only?
Thank you all.
Shouldn't composer automatically execute this method?
No, it shouldn't. Composer is a package and dependency manager program. It's job is to
Get PHP files into your vendor folder
If using those PHP files means you need other PHP files, get those other PHP files into your vendor folder
Setup things so that class files from the packages are correctly autoloaded in PHP (i.e. no need to require or include stuff yourself)
Composer packages work independent of frameworks. Someone could distribute a laravel service provider via a computer package, or someone could distribute code that doesn't know anything about Laravel. How each composer package works is up to the author (always read the README)
In the case of pagseguro/php, it looks like you're supposed to instantiate a PagSeguroPaymentRequest object which, when autoloaded, will automatically call init. The examples distributed with the package also makes it look like this package was code that predated composer, and still uses many manual includes and requires.
I'd like to run phpunit on an external server, the feed those results into a Jenkins plugin like the Clover PHP Coverage Report action.
The code base has some library dependancies that the owner of the Jenkins server does not want deployed.
Well with some tweaking I guess it is possible to make use of the monitoring external plugin. You will have to figure something out to get the files on the jenkins server.
An other option is, if the server owner is willing, to create a specific build agent for your needs. That doesn't affect his jobs and you can use your builds like you want.
Yes, library dependencies shouldn't be installed globally on a Jenkins server, but this is where Composer comes into play: You'd essentially install exactly the dependencies your current software needs locally in the workspace of your job.
Nobody should be bothered by this, because you could also include the needed library code there manually - or even worse, you could use the same file and class names and code something entirely different. All of this must not interfere with any other job running on that same server, and it doesn't.
You can't really avoid Composer, because PHPUnit will stop being distributed via PEAR, as well as some Symfony components that are being used. Better go to the Composer project page and learn how to use it. By the way: You can include the needed version of PHPUnit with Composer as well, so you need not rely on a centrally installed version (which is hard to update because there are so many jobs that would need updates then - too much work in one go).
I'm planning on creating a bunch of PHP scripts in a phar archive (for easy deployment) and allowing it to self-update from a known repository.
How should a phar archive, on a live website, update itself? Not update its contents, but just replacing itself (from a new.phar previously downloaded to /tmp or something) would be enough.
I'm specifically concerned about pitfalls on "replacing myself" in PHP, also considering requests could be underway (the script will primarily be called from the web, by AJAX).
You can check how composer does self update:
https://github.com/composer/composer/blob/master/src/Composer/Command/SelfUpdateCommand.php
But like #OddEssay said it would probably be better to use composer as package manager.
Check Distributing CLI PHP App with Ease article.
There is also mentioned PHP-Phar-Update package, that handle PHAR self-updating.
For implementation example, you can check Self-update command of PhpDocumentor
I am developing a Facebook app using heroku. My app needs the ability to upload files (pictures) to a folder on a remote server, and I assume ftp is the best option. Unfortunately the ftp extension is not enabled out of the box. I spoke with support and they suggested the following:
"We unfortunately don't support FTP, or any PHP extension at this moment.
But the good news is that we just open sourced our PHP build pack, so you could try to vendor it yourself:
https://github.com/heroku/heroku-buildpack-php"
So I am assuming I can follow the readme instructions in the link above, and simply include the --enable-ftp option?
This is a bit beyond my current knowledge. I really appreciate the help, and look forward to learning something new.
I had to do something similar. Here's what I did:
1.You need to use a custom buildpack which installs the pear packages Net_FTP. I suggest that you fork the one I've been using (https://github.com/antonyevans/heroku-buildpack-php/)
Then you need to change bin/compile. Key changes are the removal of the lines (around 163):
php/bin/pear install mail
php/bin/pear install Net_SMTP
And the addition of Net_FTP extension:
php/bin/pear install Net_FTP
2.Then you need to tell your application to load the package:
require_once 'Net_FTP.php';
Your biggest problem is that the Heroku file system is emphemeral. I would suggest going back and looking at your architecture again.