“Laravel”的版本间的差异

来自tomtalk
跳转至: 导航搜索
查找关联是否存在
Tom讨论 | 贡献
Lumen 5.2 中配置邮件
第300行: 第300行:
  
 
https://laravel-china.org/topics/1974
 
https://laravel-china.org/topics/1974
 +
 +
=Laravel 5.5 LTS=
 +
 +
距离上一代 LTS (即 5.1)感觉已经好遥远了呢!
 +
 +
* Laravel Horizon ,它为Laravel Redis队列提供了一个漂亮的仪表板和代码驱动的配置系统。Horizon的仪表板是一个Vue单页应用,可以使用命令composer require laravel/horizon直接安装进已有的应用中。它提供队列工作负载、最近作业、失败作业、作业重试、吞吐量和运行时指标、进程计数的实时显示。
 +
* 我们再熟悉不过的PHP错误处理框架,有一个漂亮拉风的错误页面。
  
 
=技术文章收藏=
 
=技术文章收藏=

2017年10月24日 (二) 06:19的版本

目录

起步

安装

  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运行效率最高。

ngnix配置文件路径

/etc/nginx

Swagger-php

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"
# or
composer global require "laravel/lumen-installer"

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

创建Lumen运用程序

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

lumen new app_name

部署到Web服务器

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

Lumen (5.2.8) (Laravel Components 5.2.*)

Creating custom helpers

Add the helpers.php file to your composer.json autoload files.

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "Tasky\\": "app/"
    },
    "files": [
        "app/Support/helpers.php"
    ]
},
$ composer dumpautoload

base64

Repository模式

为了保持代码的整洁性和可读性,使用Repository Pattern 是非常有用的。使用repositories使我们的Controller层不再那么啰嗦、更加解耦和易读。

杂项

获取版本号

$app->get('/', function () use ($app) {
    return $app->version();
});

指定302跳转

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

laravel 怎么截取字符串多余的用省略号表示?

str_limit($value, $limit = 100, $end = '...');

查找关联是否存在

$orders = Product_order::whereHas('user', function ($query) use ($name) {
    if ($name !== '') {
        $query->where('username', 'like', "%{$name}%");
    }
})->with('product')->where(function ($query) use ($order_number) {
    if ($order_number !== '') {
        $query->where('order_number', 'like', "%{$order_number}%");
    }
})->orderBy('id', 'desc')->paginate(10);

查看Laravel版本号的三种方法

1. PHP artisan --version

2. vim vendor/laravel/framework/src/Illuminate/Foundation/Application.php

3. 可以写在路由里。5.4版本的路由文件夹是routes。我们可以写在routes\web.php里。

Route::get('laravel-version', function(){
    $laravel = app();
    return "Your Laravel version is ".$laravel::VERSION;
});

Lumen 5.2 中配置邮件

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

Laravel 5.5 LTS

距离上一代 LTS (即 5.1)感觉已经好遥远了呢!

  • Laravel Horizon ,它为Laravel Redis队列提供了一个漂亮的仪表板和代码驱动的配置系统。Horizon的仪表板是一个Vue单页应用,可以使用命令composer require laravel/horizon直接安装进已有的应用中。它提供队列工作负载、最近作业、失败作业、作业重试、吞吐量和运行时指标、进程计数的实时显示。
  • 我们再熟悉不过的PHP错误处理框架,有一个漂亮拉风的错误页面。

技术文章收藏

日期及时间处理包 Carbon 在 Laravel 中的简单使用

十个Laravel5程序优化技巧

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