Symfony 4 run slowly on windows 10 - php

I installed symfony 4 on windows machine. I created a controller and returned json data. I sended request in postman and response time is 1-5 second. It's very slowly this response time.
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class ScrapingController
* #package App\Controller
* #Route("/scraping")
*/
class ScrapingController extends AbstractController
{
/**
* #Route("/", name="scraping", methods={"GET"})
*/
public function index(){
return $this->json(['test'=>'ok']);
}
}
I run the project with this command.
php -S 127.0.0.1:8000 -t public/
would you help me with this topic?

Related

Doctrine\Persistence\Mapping\MappingException: File mapping drivers must have a valid directory path, however the given path seems to be incorrect

I'm running unit tests via docker like thus
doby phpunit
docker-compose run --rm -v $SSH_AUTH_SOCK:/tmp/ssh_auth_sock -e SSH_AUTH_SOCK=/tmp/ssh_auth_sock php bash -c 'bin/phpunit --filter SendEmailsCommandTest'
I receive the following error
Doctrine\Persistence\Mapping\MappingException: File mapping drivers must have a valid directory path, however the given path [/var/source/application/models/Content.php] seems to be incorrect!
Content.php
<?php
namespace MyDomain\Model;
use Exception as ModelException;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* #ODM\Document(
* db="mydb",
* collection="Content"
* )
*/
class Content
{
/** #ODM\Id */
protected $id;
/**
* #ODM\Field(type="string")
*/
protected $contentId;
/**
* #ODM\Field(type="string")
*/
protected $content;
...
}
I've logged into the running docker container and the files exist in the path above.
/var/source/application/models
- Content.php
- ...
Has anyone had a similar problem running tests through docker and doby?

Why do Laravel Artisan Commands use so much Memory?

On a fresh Laravel install I created an Artisan command that just prints the memory usage.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MemoryTest extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'memory:test';
/**
* Execute the console command.
*
* #return int
*/
public function handle()
{
$this->info(memory_get_usage()); // 17807760 -> 17 mb
}
}
When I run this command, the memory usage is 17mb.
If I make an HTTP request on a fresh Laravel install and print the memory usage it is 1038648 (1mb).
Also, if I run php artisan tinker then run memory_get_usage() I get 24247168 (24mb).
Why is the memory usage of Artisan commands so much higher than HTTP requests?

Why Laravel 5.8 dispatch with database driver works like sync?

I changed the queue driver in .env and config/queue.php from sync to database. Then I ran php artisan cache:clear.
I created a new job with the command php artisan make:job SendEmailJob
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Mail\SendEmailMailable;
use Illuminate\Support\Facades\Mail;
class SendEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
Mail::to('hello#example.com')->send(new SendEmailMailable());
}
}
Then I wrote this route in routes\web.php
use App\Jobs\SendEmailJob;
use Carbon\Carbon;
use Illuminate\Bus\Dispatcher;
Route::get('sendEmail', function(){
$job = (new SendEmailJob())->delay(Carbon::now()->addSeconds(5));
dispatch($job);
return 'Email is sent properly';
});
I stopped php artisan serve, the started again.
I chacked the result of env('QUEUE_DRIVER', 'database');, it returns database.
I ran php artisan queue:work, but there is no output.
The email sent to SMTP server like sync driver.
Is there anything I missed?
My PHP version is 5.6.
It was a PHP version problem. I Upgraded PHP to version 7.1 and problem solved.

My custom service provider doesn't work in laravel

I have created a custom service provider in my app called DemoServiceProvider in app/providers directory , and i register it in config/app as App\Providers\DemoServiceProvider::class
here is my DemoServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class DemoServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
dd("test");
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
//
}
}
the problem is i don't see "test" ,did i miss something ?
I have replicated your code and I retrieve:
php artisan serve --port=4433
"test"
Have you tried already:
composer dumpautoload
php artisan cache:clear
ok i found the solution ,it was with these two commands php artisan clear-compiled and php artisan cache:clear .

Lumen make:command

I'm trying to execute code within my Lumen install via the command line. In full Laravel , I've read that you can use commands to achieve this via "make:command", but Lumen does not seem to support this command.
Is there anyway to enable this command? Failing that, what's the best way of running code from the CLI in Lumen?
Thanks
You can use the artisan CLI in Lumen as the same way as in Laravel but with fewer built-in commands. To see all built-in commands, use the php artisan command in Lumen.
Although there is no make:command command at Lumen, you can create your custom command:
Add new command class inside the app/Console/Commands folder, you can use the sample class template of the framework serve command
Register your custom command by adding your created class to the $commands member inside the app/Console/Kernel.php file.
Except the command generating, you can use the Laravel docs for commands when working with Lumen.
Here is a template for a new command.
You can just copy and paste this in to a new file and start working.
I tested it on lumen 5.7.0
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class CommandName extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'commandSignature';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$this->info('hello world.');
}
}
Then register it on the Kernel.php file.
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
\App\Console\Commands\CommandName::class
];
When you create your command class use this:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
Instead of what was described above about using serve command example

Categories