Sometime ago I've used ubuntu image for PHP files generation via protoc lib and it generates some metadata classes with normal hashes used by protobuf.
It was generated smth like:
namespace MyApp\ProtobufMetadata\Schema\v1;
class Request
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(hex2bin(
"0acd010a236170692f636174616c6f672f736368656d612f76312f726571756573742e70726f746f121d6170692e636174616c6f672e736368656d612e76312e72657175657374221d0a0a47657452657175657374120f0a0776657273696f6e18012001280d4260ca022d4350515c5368617265645c53657276696365735c436174616c6f675c536368656d615c76315c52657175657374e2022d4350515c5368617265645c50726f746f6275664d657461646174615c436174616c6f675c536368656d615c7631620670726f746f33"
), true);
static::$is_initialized = true;
}
}
But now I need to use alpine usage.
I've created Dockerfile with installing protobuf from github:
ENV PROTOBUF_VERSION 3.19.4
ENV PROTOBUF_URL https://github.com/google/protobuf/releases/download/v"$PROTOBUF_VERSION"/protobuf-cpp-"$PROTOBUF_VERSION".zip
RUN curl -L -o protobuf.zip "$PROTOBUF_URL"
RUN unzip protobuf.zip && cd protobuf-"$PROTOBUF_VERSION" && ./configure && make -j$(nproc) && make install
RUN cd .. && rm protobuf.zip
But after this when I generates new classes it generates metadata classes in some strange view:
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: api/schema/v1/request.proto
namespace MyApp\ProtobufMetadata\Schema\v1;
class Request
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
�
#api/schema/v1/request.protoapi.schema.v1.request"
GetRequest
version (
B`�-MyApp\\Services\\Catalog\\Schema\\v1\\Request�-MyApp\\ProtobufMetadata\\Catalog\\Schema\\v1bproto3'
, true);
static::$is_initialized = true;
}
}
Does anyone hit with similar problem?
Is any way to fix lib installation or some compile to return pretty code with hex2bin usage?
compilation was made via commands with RoadRunner usage:
[ -f ./protoc-gen-php-grpc ] || ./rr get-protoc-binary
&& chmod +x ./protoc-gen-php-grpc
&& ./rr compile-proto-files"
Host system is MacOS
This was done on purpose, your Alpine is probably just running a more recent version of protoc.
Here is the PR which removed the hex2bin call: https://github.com/protocolbuffers/protobuf/pull/8006
Related
In my composer.json I have a script called tests that is just an array of several commands for testing tools.
One of those commands is pretty slow and somewhat unimportant. So I would like to run it only occasionally and not always (whole composer tests is run as pre-commit hook)
I had an idea of doing something like
"scripts": {
"slowScript": "rand(0,10) != 5 || actualSlowScript"
}
but I can't get it to work. The script needs to be platform independent as we use different OS.
Do you have an idea on how to get it working?
This is a solution:
Create a PHP class with static method as in https://getcomposer.org/doc/articles/scripts.md#defining-scripts
<?php
namespace ComposerScripts;
use Composer\Console\Application;
use Composer\Script\Event;
use Symfony\Component\Console\Input\ArrayInput;
final class RandomLint
{
public static function runLintAtRandom(Event $event): void
{
$random = random_int(1, 5);
if ($random === 1) {
$event->getIO()->write('Lint skipped');
return;
}
$input = new ArrayInput(array('command' => 'lint'));
$application = new Application();
$application->setAutoExit(false);
$application->run($input);
}
}
then define the script as
"scripts": {
"test": [
"ComposerScripts\\RandomLint::runLintAtRandom",
"secondScript",
"#thirdOne"
]
}
and you can control scripts from PHP Class. I can see quite some potential in this solution.
I would not build it into the test script because then you can never force the test to run when you want, like in a build pipeline. You can do it via the composer scripts feature by using the exit status of a shell command:
"scripts": {
"slowScript": "[ $(rand -M 5) -eq 0 ] && actualSlowScript"
}
Assuming you have the rand command installed, this picks a random number between 0 and 4, then only runs the test if it picked 0.
Note this will throw a composer warning 80% of the time. If that's problematic, you could do something like this:
"scripts": {
"slowScript": "if [ $(rand -M 5) -eq 0 ]; then actualSlowScript; else echo skipping slow test; fi"
}
Sorry, pretty noob to psysh.
Basically I have this function in my psysh/php:
>>> show $newcsr
class Tokyo {
private function sign($caCert,$userCsr) {
$caKey = file_get_contents('/home/nairobi/ca.key');
$userCert = openssl_csr_sign($userCsr, $caCert, $caKey, 365, ['digest_alg'=>'sha256']);
openssl_x509_export($userCert, $userCertOut);
return $userCertOut;
}
}
How do I call sign function to generate me a certificate in psysh console?
Psysh provides a sudo command for bypassing visibility restrictions, so you can do: sudo $newcsr->sign($caCert,$userCsr);
I am trying to build an angular project from a Laravel project.
When I run an exec command from Laravel I got env: node: No such file or directory
Steps to reproduce :
create Laravel project: laravel new laravel-bug
create angular project: ng new angular-bug
In the Laravel file routes/web.php, in the / route, add:
use Symfony\Component\Process\Process;
$process = new Process('cd /path/to/angular-bug && ng build');
$process->run(function ($type, $buffer) {
if (Process::ERR === $type) {
echo 'ERR > '.$buffer;
} else {
echo 'OUT > '.$buffer;
}
});
This will output the result, which for me is env: node: No such file or directory
Any ideas ?
I've had this issue before when node wasn't in the path of the web server user. The second argument to the Process::run() method is an array of environment variables. Use it to set a path.
<?php
use Symfony\Component\Process\Process;
$env = ["PATH" => "/sbin;/bin:/usr/sbin:/usr/bin:/path/to/node/if/its/different"];
$process = new Process('cd /path/to/angular-bug && ng build');
$process->run(function ($type, $buffer) {
if (Process::ERR === $type) {
echo 'ERR > '.$buffer;
} else {
echo 'OUT > '.$buffer;
}
}, $env);
The problem is that somewhere in this build process something is just calling node and expecting it will be in the path. (I think I experienced it when running npm.) This is not a great thing to do, and the software should be aware of where it’s located due to a compile-time setting or information from the package management system, or it should attempt to locate it.
I am working on notification using webpush. i used this link to implement notificaton web push.I am searching and applying every solution from last week but same problem
I installed gmp and i added in xampp/etc/php.ini
extension = mcrypt.so
This is my code
class InvoicePaid extends Notification implements ShouldQueue
{
use Queueable;
public $title, $body;
public function __construct($title, $body)
{
//
$this->title = $title;
$this->body = $body;
}
public function via($notifiable)
{
return [WebPushChannel::class];
}
public function toWebPush($notifiable, $notification)
{
$time = \Carbon\Carbon::now();
return WebPushMessage::create()
// ->id($notification->id)
->title($this->title)
->icon(url('/push.png'))
->body($this->body);
//->action('View account', 'view_account');
}
}
My route is
Route::post('/send-notification/{id}', function($id, Request $request){
$user = \App\User::findOrFail($id);
$user->notify(new \App\Notifications\GenericNotification($request->title, $request->body));
return response()->json([
'success' => true
]);
});
But when i send notification i got this error
This is picture of gmp installation
Ubuntu 18.04, PHP 7.4. Solved by following commands:
sudo apt install php7.4-gmp
sudo service php7.4-fpm restart
Try to go to your xampp/php/ext folder
check if php_gmp.dll exists
open xampp/php/php.ini
search for php_gmp and make sure it's like extension=php_gmp.dll instead of ;extension=php_gmp.dll
else
download php_gmp.dll to the folder and try the procedure again
You should not have gmp issue again.
I am experiencing an interesting strange issue with shell_exec...
Description
I develop PHP web app that uses C++ backend app for calculations. Server is running on linux and I use shell_exec for C++ program execution. I updated version of my C++ app and since then shell_exec doesn't work, but
I've checked both versions of C++ app have 777 rights
Both versions run flawlessly from a console
Both versions were tested for same data
Both versions were tested on two different PCs/webservers with same results
For both versions the webapp PHP frontend is exactly the same
Second version (that can't be launched) runs faster then previous one
Questions
Have you ever experienced a similar problem?
Is it possible that in shell_exec a problem could occur, that during standard execution from console doesn't?
Piece of PHP code
class LauncherManager extends Nette\Object {
private $wwwDir;
private $db;
private $f;
public function __construct($wwwDir, \DibiConnection $db) {
$this->wwwDir = $wwwDir;
$this->db = $db;
$this->f = (new Dao\DaoFactory())->setDb($db);
}
public function execMeasurement($measurementId) {
$this->execGenetrac(" -m $measurementId");
}
public function execSamples($analysisId) {
$this->execGenetrac(" -s $analysisId");
}
public function execAnalysis($analysisId) {
$this->execGenetrac(" -a $analysisId");
}
public function execGenetrac($params) {
// Check path to genetrac can be set
$path = $this->wwwDir . "/genetrac";
$this->checkPathExist($path);
// Check library path
$lib = './lib';
$expl = 'export LD_LIBRARY_PATH="' . $lib . '"';
$this->checkPathExist($path . "/" . $lib);
// Check genetrac executable exist
$this->checkPathExist($path . "/genetrac");
// Launch genetrac with parameters
$this->exec("cd $path; $expl; ./genetrac $params");
}
public function exec($command) {
return shell_exec($command);
}
...
shell_exec returns NULL in two situations:
an error occurs
executed program returns no output
In order to distinguish these situations use exec() instead:
public function exec($command) {
exec($command, $arrOutputLines, $intReturnStatus);
return join("", $arrOutputLines);
}
You can debug this code by var_dump'ing $arrOutputLines and $intReturnStatus (these are the array of lines that your program printed out and the numeric exit status of your program (0 usually means OK, non-zero means error)).