“Laravel”的版本间的差异

来自tomtalk
跳转至: 导航搜索
Homestead
Tom讨论 | 贡献
Is Laravel really this slow?
第33行: 第33行:
  
 
==Is Laravel really this slow?==
 
==Is Laravel really this slow?==
 +
 +
http://stackoverflow.com/questions/23283574/is-laravel-really-this-slow
  
 
I just started using Laravel. I've barely written any code yet, but my pages are taking nearly a second to load!
 
I just started using Laravel. I've barely written any code yet, but my pages are taking nearly a second to load!

2017年1月5日 (四) 02:09的版本

目录

起步

安装

  1. 下载Laravel一键安装包。
  2. 配置Web服务器虚拟主机。
  3. 将网站根目录配置为laravel5/public。
  4. 能显示Laravel文字,说明安装成功。

Homestead

https://phphub.org/topics/2 Laravel 的 Homestead 开发环境部署

这是两年前的旧文了,不知现在是否还有效。

设置数据库连接

本机连接 vm 里 mysql 方法是:

host: 127.0.0.1

port: 33060

user: homestead

pass: secret

Is Laravel really this slow?

http://stackoverflow.com/questions/23283574/is-laravel-really-this-slow

I just started using Laravel. I've barely written any code yet, but my pages are taking nearly a second to load!

Reply 1

Laravel is not actually that slow. 500-1000ms is absurd; I got it down to 20ms in debug mode.

The problem was Vagrant/VirtualBox + shared folders. I didn't realize they incurred such a performance hit. I guess because Laravel has so many dependencies (loads ~280 files) and each of those file reads is slow, it adds up really quick.

kreeves pointed me in the right direction, this blog post describes a new feature in Vagrant 1.5 that lets you rsync your files into the VM rather than using a shared folder.

There's no native rsync client on Windows, so you'll have to use cygwin. Install it, and make sure to check off Net/rsync. Add C:\cygwin64\bin to your paths.

Reply 2

From my Hello World contest, Which one is Laravel? I think you can guess. I used docker container for the test and here is the results

To make http-response "Hello World":

Golang with log handler stdout : 6000 rps

SpringBoot with Log Handler stdout: 3600 rps

Laravel 5 with off log :230 rps

Mac安装

http://laravel-china.org/docs/5.1/homestead 按开发文档步骤安装,比较顺利。

  1. 安装Virtual Box
  2. 安装Vagrant
  3. 下载本地Lavravl项目代码
  4. 配置Homestead.yaml
  5. vagrant up
  6. vagrant reload --provision
  7. vagrant destroy --force

Windows安装

windows的安装步骤与Mac一样,只是电脑配置差异,有些问题要特别处理。


在BIOS中,开启虚拟化。

安装好Virtual Box、Vagrant,配置好Homestead.yaml后,vagrant up启动到一半不动了,直到超时退出。


在配置文件夹和站点目录

folders的map和to,配置反了,启动时vagrant找不到github_projets目录。

folders:
    - map: d:/github_projects
      to: /home/github_projects
 
sites:
    - map: laravel.example.com
      to: /home/github_projects/LaravelExample/public


运行composer install

正常启动Vagrant后,打开站点首页,报错,指示vendor目录下的文件找不到。


.ssh帐户可以注释掉
authorize: ~/.ssh/id_rsa.pub
 
keys:
    - ~/.ssh/id_rsa


cpus设置

i5CPU,双核四线程,跑了个负载。

ab -c 50 -n 2000 http://laravel.example.com/
 
cpus: 1    75.99     72.95
cpus: 2   111.95    114.54
cpus: 3   111.27    115.85
cpus: 4    92.57     95.45

从测试结果上看,cpus设为2运行效率最高。

SwaggerLume

https://github.com/DarkaOnLine/SwaggerLume

一、安装swagger包

composer require "darkaonline/swagger-lume 1.*"

二、为swagger配置lumen

// bootstrap/app.php
$app->withFacades();
 
// add this line before Register Container Bindings section:
$app->configure('swagger-lume');
 
// add this line in Register Service Providers section:
$app->register(\SwaggerLume\ServiceProvider::class);

三、配置及生成swagger

php artisan swagger-lume:publish-config (config/swagger-lume.php)
php artisan swagger-lume:publish
php artisan swagger-lume:generate

四、指定swagger路由

//config/swagger-lume.php
'routes' => [
    'api' => 'api-docs', // from 'api/documentation'
    'docs' => 'docs',
],

五、设置自动更新文档

//config/swagger-lume.php
 'generate_always' => env('SWAGGER_GENERATE_ALWAYS', true),

如果不设置,要手动执行swagger-lume:generate命令,文档才能看到最新变化。

Lumen

安装

安装composer

https://getcomposer.org/download/ 上下载安装文件。

利用Composer下载Lumen安装器

composer global require "laravel/lumen-installer=~1.0"

安装时包名写错了,留下包痕迹清除不了,把composer卸载,重新安装后,才能用正确的包名安装lumen。

创建Lumen运用程序

通过lumen new命令就能在你指定的目录中创建一个干净的Lumen应用程序骨架了。

lumen new app_name

部署到Web服务器

Lumen 几乎不需要任何配置就能开箱即用。你能立即开始你的编码工作了!

Lumen (5.2.8) (Laravel Components 5.2.*)

base64

杂项

指定302跳转

use Illuminate\Http\RedirectResponse;
return redirect('/userInfo', 302); //默认为301

Lumen 5.2 中配置邮件

https://laravel-china.org/topics/1974

技术文章收藏

十个Laravel5程序优化技巧

如何查看 Laravel 5 的所有数据库请求