symfony pass arguments to command line script - php

I have been creating web application using symfony, I want to run commande line instead of run URL inside browser.
composer.json:
"import-data": [
"curl http://localhost:8000/importusers?username=client1"
]
When I run : composer import-data it works fine,
but how I can pass client1 as an argument in this command.
thank you.

Related

WSL2 Laravel dusk testing google-chrome driver unable to display site

Laravel Dusk, errors loading google-chrome
I am trying to run tests using Laravel Dusk on a Windows 10 subsystem, WSL2 running Ubuntu. I've followed the installation guides, and I'm stuck at the point after the google-chrome browser is loaded and renders the site:
This is my DuskTestCase.php driver method:
protected function driver()
{
$options = (new ChromeOptions)->addArguments(collect([
])->unless($this->hasHeadlessDisabled(), function ($items) {
return $items->merge([
'--disable-gpu',
// '--headless',
'--window-size=1920,1080'
]);
})->all());
return RemoteWebDriver::create(
$_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
Before running the test, I run chromedriver for linux
vendor/laravel/dusk/bin/chromedriver-linux
returns:
Starting ChromeDriver 99.0.4844.51 (d537ec02474b5afe23684e7963d538896c63ac77-refs/branch-heads/4844#{#875}) on port 9515
Next I run any test say AuthTest
php artisan dusk tests/Browser/AuthTest.php
The test cannot render the site: http://localhost:9515
Error in browser:
{"value":{"error":"unknown command","message":"unknown command: unknown command: login","stacktrace":"#0 0x55bf14b857d3 \u003Cunknown>\n#1 0x55bf148e1688 \u003Cunknown>\n#2 0x55bf14932e11 \u003Cunknown>\n#3 0x55bf14932b77 \u003Cunknown>\n#4 0x55bf148b81d4 \u003Cunknown>\n#5 0x55bf148b9020 \u003Cunknown>\n#6 0x55bf14bb649d \u003Cunknown>\n#7 0x55bf14bcf60c \u003Cunknown>\n#8 0x55bf14bb8205 \u003Cunknown>\n#9 0x55bf14bcfee5 \u003Cunknown>\n#10 0x55bf14bac070 \u003Cunknown>\n#11 0x55bf148b7d49 \u003Cunknown>\n#12 0x7f7d460390b3 \u003Cunknown>\n"}}
If I load google-chrome manually and try to go to the same address (http://127.0.0.1:9515/), the same error appears.
However if I close everything and run:
php artisan serve --port 9515
then
google-chrome
I am able to manually interact with the site, yet Laravel Dusk cannot load the browser.
The following error is thrown by Laravel Dusk
```bash
TypeError: Argument 1 passed to Facebook\WebDriver\Remote\DesiredCapabilities::__construct() must be of the type array, null given, called in /home/simon/sites/acquisitionboardgame_vue/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php o
n line 648
Can anyone point me in the right direction ?

CURL is enabled in PHP but disabled in Laravel

I want to use CURL in my Laravel 5.3 app but it returns error :
Call to undefined function App\Http\Controllers\curl_init()
I created info.php file to test curl contains :
<?php
var_dump(function_exists('curl_version'));
phpinfo();
?>
it returns true and shows that curl is enabled :
but when I test it inside laravel :
dd(function_exists('curl_version'));
it returns false !!
When I run php --ini in terminal it returns :
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_curl.dll' - /usr/lib/php/20151012/php_curl.dll: cannot open shared object file: No such file or directory in Unknown on line 0
I tried to use curl_init() in info.php outside laravel and it works!
Why does this happen and how to fix it ?
In your error message PHP tries to resolve the curl_init function within the App\Http\Controllers namespace. If the underlying issue is not related to the PHP Warning you later pasted, the curl functions should work if you prefix them with backslash, like \curl_init.
This way you're telling PHP that the function resides within the top level namespace, not within App\Http\Controllers
I was running Laravel with:
php artisan serve --host 0.0.0.0
but when I changed it to :
php artisan serve --host my_private_IP
it's working now.

laravel controller shell_exec('composer update');

I would like to execute the following command : composer update in my controller in laravel, however this one does not work.
On the other hand the command composer info works perfectly.
When I execute composer update in a command prompt all my dependencies are correctly updated in the laravel vendor file but when I try to execute composer update in my controller nothing happens.
here is my code :
$data['output'] = shell_exec( 'cd '. base_path() .' && composer update' );
dd($data);
and here is the result :
array:1 [▼
"output" => null
]
Could you help me to understand why composer update does not work in a controller ?
I would like to update my dependencies in a controller without the command prompt.
Thank you.
From the php docs for shell_exec():
The output from the executed command or NULL if an error occurred or the command produces no output.
Sounds like you'd be better off using passthru() instead as that will give you the erroneous output.
Speaking of erroneous, this is idea sounds like a recipe for unmitigated disaster.

NotFoundHttpException in RouteCollection.php line 161 laravel 5.2

I'm new on laravel , I didn't write any code yet but when I open my project it gives me this error , anyone can help me to solve it ?
[
Just try http://localhost:8000 since it seems like you already started development server in your local machine using php artisan serve while you were on your project root via terminal.
Or you can try from begining:
Go to your project root from terminal / cmd
Run php artisan serve
Now try http://localhost:8000 which is equivalent to http://localhost/laravel/public , considering laravel is your project folder name.

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Error in Laravel

I was trying to access http://localhost:8000/phpmyadmin for database in laravel. But it's showing the following error:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Open:
C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php
$others = $this->checkForAlternateVerbs($request);
if (count($others) > 0) {
return $this->getOtherMethodsRoute($request, $others);
}
throw new NotFoundHttpException;
I used following command to open my server and it automatically open with 8000 port that's why i have to use
http://localhost:8000/phpmyadmin
php artisan serve
So, if anyone know the solution, please reply.
If you have phpmyadmin properly installed and configured on your local, you should just access it from http://localhost/phpmyadmin with or without your laravel application running on http://localhost:8000, that make no difference.
Also, every URI you will try tro access after http://localhost:8000/ will be considered as a route of your laravel application.
Access http://localhost:8000/phpmyadmin involves you have a route like Route::get('/phpmyadmin', /** ... /*);
If you doesn't have phpmyadmin installed and accessible on your local, download it and follow the instructions to make it accessible from your web server.
The php artisan serve command run the PHP built-in server.
It doesn't use your apache (XAMPP) webserver, but the web server provided by php.
See PHP built-in server
Make sure you have a route setup for phpmyadmin in your routes.php
Route::get('/phpmyadmin', function () {
return 'Nothing here';
});
This will not give you the phpmyadmin though.

Categories