Problem with the installation of Spatie on Windows - php

I'm trying to configure Spatie/Browsershot for a project, written in Laravel but after completing all of the steps, I still get one error:
'node' is not recognized as an internal or external command, operable program or batch file
A have installed the latest versions of node and npm and the both of them exist in the PATH and work on cmd as well.
Like it's written in the official documentation on GitHub, I've ran:
npm install puppeteer
composer require spatie/browsershot
In the code I've written:
use Spatie\Browsershot\Browsershot;
//Method to generate some random id
$unique_id = uniqid('img_');
//The path to the node and npm folders
$path_node = realpath('C:\\"Program Files"\\nodejs');
$path_npm = realpath('C:\\Users\\Hristo\\AppData\\Roaming\\npm');
//The $content is actually a stored HTML code
Browsershot::html("$content")->setScreenshotType('jpeg', 100)
->setNodeBinary($path_node)
->setNpmBinary($path_npm)
->save("$unique_id.jpeg");
Program Files is with double quotation marks, otherwise Laravel throws me an error because of the white space in between the two words.
I'm not sure about the paths, are they correctly written? (the problem with the backslashes in windows)

This little snippet helped me with the problem. As long as OS environmental variables are pointing to the node.exe file you can put this into your code
->setNodeBinary('PATH %~dp0;%PATH%;') //~dp0 : fetches current directory path in windows
Hope you get it solved

If you can run node -v and get the version of your node. Then, the error was caused by the space between "Program Files". To solve this:
Create a new folder in your local disk (C:), i.e. Programs
Move your the Node folder to the folder you just created.
Change the Node "Path" in the "User Variable" inside the "Environment Variable" i.e. C:\Programs\nodejs. NOTE: ONLY THE DIRECTORY CONTAINING THE .exe FILE IS NEEDED NOT THE FILE.
You can then use the path for the "setNodeBinary" i.e. "C:\Programs\\nodejs\\node.exe". NOTE: THE .exe FILE IS REQUIRED HERE
This should be able to solve the issue.

Related

Binance PHP API

I try to get this done from github. https://github.com/binance-exchange/php-binance-api
I installed Xampp (latest version: 7.2.3) on a win 10 machine. Xampp is running. (at least not mysql, because it has an error while starting, but mysql is not needed). I downloaded the files from github and puttet them into my htdocs in a new folder called "binance". I downloaded the install-file for composer from here: https://getcomposer.org/doc/00-intro.md#installation-windows Installed it and choosed the php.exe out of my xampp folder inside the installation-process.
Composer starts out of the console, and it works. I put this command into the cmd:
php composer.phar require "jaggedsoft/php-binance-api #dev"
It installs some folders and files, into my project-directory. it's right.
Inside of the files downloaded from github, there is a file called:
php-binance-api-test.php
Inside this file, there are different lines like:
require 'vendor/autoload.php';
file_put_contents( getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json"
But he is not able to find ".config/jaggedsoft/" because there is no folder named .config. There is also no file named php-binance-api.json only one called php-binance-api.php
I would be really thankful, if someone may try to get this run an tell me, what I have done wrong.
I have had the same problem on my Ubuntu server and I could solve it by setting HOME directory at the top of my scripts as:
putenv("HOME=/var/www/html/");
My config is at a directory of
/var/www/html/.config/jaggedsoft
File name is php-binance-api.json and file content is:
{
"api-key": "ApiKeyHere",
"api-secret": "ApiSecretHere"
}

Uncaught Exception: Unable to locate Mix file

I am trying to run a laravel app in my local system. I have followed the https://gist.github.com/hootlex/da59b91c628a6688ceb1 link. I run the command php artisan serve command, and when I browse it, then produces the error
PHP Fatal error: Uncaught Exception: Unable to locate Mix file: /css/vendor.css. Please check your webpack.mix.js output paths and try again. in /var/www/html/laravel-app/app/helpers.php:439
In the specified line of helpers.php, it has
if (! isset($manifest[$path])) {
throw new Exception(
"Unable to locate Mix file: {$path}. Please check your ".
'webpack.mix.js output paths and try again.'
);
}
public/mix-manifest.json
{
"/mix.js": "/mix.js"
}
I couldn't sort it out. Please help. Thanks
The blade file you're loading obviously has mix('/css/vendor.css') call. You either comment out this line(s) or install npm then build your assets.
Your manifest file doesn't have /css/vendor.css but if you check your blade files (views) you'll see you are calling mix('/css/vendor.css'). So if you find and comment out this line(s) your problem will be solved.
Ideally, mix() is used for loading assets that were built by webpack. It will then take care of the versioning string for you. How mix can be used is detailed in the documentation. I will refrain myself from discussing that here.
You've built your assets by running npm run dev or similar commands. And then the manifest file doesn't contain those assets mapping. And your public directory doesn't have those assets as well. Then it's safe to assume that you can remove those mix calls from your blade (views) files.
If you have the assets built in your public directory then you can load those assets by assets function.
Lastly, you should know your assets first, before loading them to your site. I get the notion that you don't have any clue where those assets came from, so you shouldn't load them in the first place.
This happened with me and after spending quite some time and effort, I did manage to figure out what was happening and how to fix it.
Here's what happens:
You update your webpack.mix.js file with the destination where you wish to publish your compiled JS and CSS files respectively.
mix.js('resources/js/app.js', 'public/js').vue();
Mix compiles and stores the hence generated CSS and JS files within their respective destination folders when you run npm run dev or npm run watch.
laravel-app (Your laravel app root folder)
\public
\css
\app.css
\js
\app.js
When you open the application in your browser with, say Valet, Laravel spits out the following error message:
Unable to locate Mix file: /js/app.js
(or)
Unable to locate Mix file: /css/app.css
Something worth noting on the Uncaught Exception screen though, is that Laravel by default attempts to look for the files at localhost:8080. Implied that Laravel is looking for the files respectively at:
localhost:8080\css\app.css
(and)
localhost:8080\js\app.js
Hence, if your hostname or port is anything other than localhost:8080, Laravel would not be able to find your files. For example, if you're using Valet, your default URL would become laravel-app.test where laravel-app is the name of your app's root folder.
But, there's a way to fix this. And it comes directly out to Laravel's documentation.
Solution (TL;DR)
In order to use a custom mix base URL, you would require to update your config\app.php file to add the following configuration value for setting the mix URL:
'mix_url' => env('MIX_ASSET_URL', 'localhost'),
With your mix_url config option set in your app.php file, you should now be able to manipulate it by adding the MIX_ASSET_URL key in your .env file and setting it to blank, so that it points to \public\js\app.js and \public\css\app.css respectively, within your project directory.
MIX_ASSET_URL=""
That solved it for me. Hope it does it for your too. Lemme know how it goes. Cheers!
Try running npm install and after that build the assets, either npm run dev or npm run watch , depends on what you are using.
In my case,
laravel 9
I should have changed the mix-manifest.json file
"/js/application.js": "/js/application.js",
"/js/admin.js": "/js/admin.js",
"/css/application.css": "/css/application.css",
"/css/admin.css":"/css/admin.css"
Delete package-lock.json.
Delete folder 'node_modules' and run 'npm install' to reinstall all modules.
Then run 'npm run watch' or 'npm run production'.
That helps me to fix that problem.
check the package.json file for the command to build the scripts and styles, normally you will have by default: npm run dev. Might happen that you will need to run:
npm rebuild node-sass
npm run dev or npm run watch
I changed my webpack.mix.js files and made these changes there and worked. Only define the specific path to public/js/app.js in webpack.mix.js
mix.js(
[
"resources/assets/js/jquery.js",
"resources/assets/js/popper.js",
"resources/js/app.js",
],
"public/js/app.js"
)
.autoload({
jquery: ["jquery", "jQuery", "$", "window.jQuery"],
Popper: ["popper", "Popper", "popper.js"],
popper: ["Popper", "popper.js"],
})
.vue()
.postCss("resources/css/app.css", "public/css", [])
.sass("resources/sass/app.scss", "public/css")
.disableNotifications(); // to disable notifications of building app;
In My case, I change
'debug' => false, to true
in the file app.config under config folder in my project to see log in my browser. Then when I run my project got error above like you. then I change to
'debug' => false again. It works.

how does composer for binance API for PHP work?

I try to get this done from github.
https://github.com/binance-exchange/php-binance-api
I installed Xampp (latest version: 7.2.3) on a win 10 machine. Xampp is running. (at least not mysql, because it has an error while starting, but mysql is not needed).
I downloaded the files from github and puttet them into my htdocs in a new folder called "binance".
I downloaded the install-file for composer from here: https://getcomposer.org/doc/00-intro.md#installation-windows
Installed it and choosed the php.exe out of my xampp folder inside the installation-process.
Composer starts out of the console, and it works.
I put this command into the cmd:
php composer.phar require "jaggedsoft/php-binance-api #dev"
It installs some folders and files, but not into my project-directory. It downloads and installs it into "user/vendor/..." on my drive c.
Inside of the files downloaded from github, there is a file called:
php-binance-api-test.php
Inside this file, there are different lines like:
require 'vendor/autoload.php';
file_put_contents( getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" ,
I copied the whole vendor directory into my project directory, so he can find his files.
But he is not able to find ".config/jaggedsoft/" because there is no folder named .config.
There is also no file named php-binance-api.json only one called php-binance-api.php
If I try to access some of the sample file, like web_socket_chart.php in examples, he gives me an fatal error:
Fatal error: Uncaught Error: Class 'React\EventLoop\Factory' not found in
...
this might be a file inside of the php-folder of xampp, but how does he load it before to get the class nedded?
I think i messed up the installation of composer? or do I have to choose other place for the project inside of xampp?
What is composer even good for? I would be really thankful, if someone may try to get this run an tell me, what I have done wrong.

phalcon installed components or not coming in cmd windows opertaing system

I have installed the phalcon in windows by adding phalcon_dll to xampp/php/ext and added extension in php.ini file now when i checked whether it installed or not i did <?php phpinfo(); ?> then i can able to see that it is installed..
Now i want to create a new skelton application through cmd when i type phalcon it should show the components as per documentation but its sayin this:
C:\Users\Amerytrech-Waheed>phalcon
'phalcon' is not recognized as an internal or external command,
operable program or batch file.
im tryig do like this: https://www.tutorialspoint.com/phalcon/phalcon_environmental_setup.htm
but little confused what are all need to add in system variables.?
and what is the alternate solution to create skelton?
Step 5 in the very document you pasted states:
After downloading the package, set the path variable in the system properties
it then explicitly shows you an image that shows the path to add, separated by a semicolon.
;C:\phalcon-devtools-master
So if you are unclear on where to set this.
Right click Computer -> Properties -> Advanced -> Environment Variables -> Path then add the path mentioned above to the very end of the path string.

Does symlinking a file change how the file is parsed in php?

I have a php application that relies on several classes to function properly. If I take one of the application's class files
/my/folder/class.php
then move it somewhere else
mv /my/folder/class.php /my/other/folder/class.php
then in its place inside of
/my/folder/
I create a symlink to it called class.php via
ln -s /my/other/folder/class.php /my/folder/class.php
I would expect my application to be unaffected, but instead this is breaking it. I know the symlink is valid since at the command line I can do
nano /my/folder/class.php
and everything looks as I would expect it to. Am I missing something fundamental about the behavior of symlinks, and/or how apache or php processes them? Is it changing the working directory or $_SERVER['DOCUMENT_ROOT']? I can not figure out why this would have any affect on my application.
I am using Apache server in CentOs.
Thanks!
The only difference would be if you are using require_once or include_once and you are mixing the symlink path with the real file path. In this instance, the X_once is going to think those files are different and load it twice (which will of course cause problems if you define any classes or functions).
Would probably need an actual error message to guess any further.

Categories