GVKun编程网logo

Laravel框架学习 -- php artisan down/up(php laravel框架 新手教程)

4

关于Laravel框架学习--phpartisandown/up和phplaravel框架新手教程的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c#–asyncasdowndowniss

关于Laravel框架学习 -- php artisan down/upphp laravel框架 新手教程的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c# – async as down down issue、IlluminateDatabaseQueryException SQLSTATE[07002] 在任何开发之前运行 php artisan migrate 后出错、Laravel "PHP Artisan route:list" 失败,目标类 [AppHttpControllersAPIAuthLoginController] 不存在、Laravel 5.0 php artisan make:model ModelName自动创建迁移类等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

Laravel框架学习 -- php artisan down/up(php laravel框架 新手教程)

Laravel框架学习 -- php artisan down/up(php laravel框架 新手教程)

    由于某种原因,公司整体框架由python的flask框架,转换为php的laravel。在断断续续几个月的时间里,边继续写着flask框架,边学着laravel。说下自己现在的状态吧。前段时间差不多都在个1-2点睡觉,大概四月份有段时间竟然到了3-4点才睡的地步。

    路漫漫其修远兮,总感觉时间不够用的。大概是自己之前浪费的时间太多了,是时候还上了。


    laravel文档中文版的,大概看到过三个。随便找个看看就可以了。http://laravel-china.org/docs/5.1 

# 输入 php artisan 即可看到全部可用命令

  down                 Put the application into maintenance mode
  up                   Bring the application out of maintenance mode

    整体流程大体(因为详细的我也不是很清楚╮(╯_╰)╭)说下吧。

一、命令的实现

    1. 作为服务提供者,加载到程序中。

// config/app.php 中。
''providers'' => [
    // 这个便是 laravel自带的 artisan 命令提供者
    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
]

    2.然后找到 Up/Down 命令入口

/**
 * Register the command.
 *
 * @return void
 */
protected function registerUpCommand()
{
    $this->app->singleton(''command.up'', function () {
        return new UpCommand;
    });
}


/**
 * Register the command.
 *
 * @return void
 */
protected function registerDownCommand()
{
    $this->app->singleton(''command.down'', function () {
        return new DownCommand;
    });
}

    3.1 DownCommand实现

class DownCommand extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = ''down'';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = ''Put the application into maintenance mode'';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        // 关键点: 在当前存储目录/framework 下面创建一个 down文件
        touch($this->laravel->storagePath().''/framework/down'');

        $this->comment(''Application is now in maintenance mode.'');
    }
}


// touch() 函数php文档解释
/**
 * Sets access and modification time of file
 * @link http://php.net/manual/en/function.touch.php
 * @param string $filename <p>
 * The name of the file being touched.
 * </p>
 * @param int $time [optional] <p>
 * The touch time. If time is not supplied, 
 * the current system time is used.
 * </p>
 * @param int $atime [optional] <p>
 * If present, the access time of the given filename is set to 
 * the value of atime. Otherwise, it is set to
 * time.
 * </p>
 * @return bool true on success or false on failure.
 * @since 4.0
 * @since 5.0
 */
function touch ($filename, $time = null, $atime = null) {}

    3.2 UpCommand 实现

class UpCommand extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = ''up'';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = ''Bring the application out of maintenance mode'';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        // 关键:删除laravel存储目录/fromework 下面的 down 文件
        @unlink($this->laravel->storagePath().''/framework/down'');

        $this->info(''Application is now live.'');
    }
}


// @unlink() php文档解释
/**
 * Deletes a file
 * @link http://php.net/manual/en/function.unlink.php
 * @param string $filename <p>
 * Path to the file.
 * </p>
 * @param resource $context [optional] &note.context-support;
 * @return bool true on success or false on failure.
 * @since 4.0
 * @since 5.0
 */
function unlink ($filename, $context = null) {}

 

二、如何工作的

    1. 当然是使用中间件了

// Http/Kernel.php 文件里面
class Kernel extends HttpKernel
{
    /**
     * The application''s global HTTP middleware stack.
     *
     * @var array
     */
    protected $middleware = [
        
        // 就是这个东西了
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    ];
}

    2. 继续看中间件的实现

class CheckForMaintenanceMode
{
    /**
     * The application implementation.
     *
     * @var \Illuminate\Contracts\Foundation\Application
     */
    protected $app;

    /**
     * Create a new middleware instance.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return void
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     *
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
     */
    public function handle($request, Closure $next)
    {
       
        // 当这个条件成立时,直接抛出 HttpException(503) 异常。
        // 默认情况下,该请求会直接显示 resources/views/errors/503.blade.php 页面
        if ($this->app->isDownForMaintenance()) {
            throw new HttpException(503);
        }

        return $next($request);
    }
}



// 再看 isDownForMaintenance() 函数

/**
 * Determine if the application is currently down for maintenance.
 *
 * @return bool
 */
public function isDownForMaintenance()
{
    // 重点:判断一下 laravel的storagePath/framework 下面是否存在 down 文件
    return file_exists($this->storagePath().''/framework/down'');
}


总结:

其实呢,这些只是一个抛砖引玉的过程。只是拿框架的一个小东西来扯扯而已。还是那句话:路漫漫其修远兮。加油吧,少年~

1.  php artisan down => 在storagePath/framework 下面创建 down文件; php artisan up => 删除 down 创建 down文件

2.  laravel 默认中间件,检查storagePath/framework 下面是否存在down文件,若存在则抛出503异常

c# – async as down down issue

c# – async as down down issue

我有一个异步asp.net控制器.该控制器调用异步方法.实际执行异步IO工作的方法深入到我的应用程序中.控制器和链中最后一个方法之间的一系列方法都用async修饰符标记.以下是我如何设置代码的示例:
public async Task<ActionResult> Index(int[] ids)
{
    List<int> listofDataPoints = dataPointService(ids);
    List<Task> dpTaskList = new List<Task>();
    foreach (var x in listofDataPoints)
    {
        dpTaskList.Add(C_Async(x));
    }

    await Task.WhenAll(dpTaskList);
    return View();
}


private async Task C_Async(int id)
{
    //this method executes very fast
    var idTemp = paddID(id);
    await D_Async(idTemp);
}

private async Task D_Async(string id)
{
    //this method executes very fast
    await E_Async(id);
}

private async Task E_Async(string url)
{
    //this method performs the actual async IO
    result = await new WebClient().DownloadStringTaskAsync(new Uri(url))
    saveContent(result);
}

正如您所看到的,控制器异步调用C_Async(x),然后有一系列异步方法到E_Async.控制器和E_Async之间有方法,并且都有async修饰符.是否存在性能损失,因为有使用异步修改器的方法但没有执行任何异步IO工作?

注意:这是实际代码的简化版本,控制器和E_Async方法之间有更多异步方法.

解决方法

是.有一个惩罚(虽然不是一个巨大的),如果你不需要异步不要.这种模式通常称为“返回等待”,您几乎总能删除异步和等待.只需返回代表异步操作的已有任务:
private Task C_Async(int id)
{
    // This method executes very fast
    var idTemp = paddID(id);
    return D_Async(idTemp);
}

private Task D_Async(string id)
{
    // This method executes very fast
    return E_Async(id);
}

在此特定情况下,Index将仅等待E_Async返回的任务.这意味着在完成所有I / O之后,下一行代码将直接返回View();. C_Async和D_Async已在同步调用中运行并完成.

IlluminateDatabaseQueryException SQLSTATE[07002] 在任何开发之前运行 php artisan migrate 后出错

IlluminateDatabaseQueryException SQLSTATE[07002] 在任何开发之前运行 php artisan migrate 后出错

如何解决Illuminate\Database\QueryException SQLSTATE[07002] 在任何开发之前运行 php artisan migrate 后出错?

我正在尝试在 IIS 上创建一个连接到 Microsoft sql Server 的 laravel 8 服务器。 但是,在设置时,尝试运行 PHP artisan migrate 会导致此错误:

 Illuminate\Database\QueryException

  sqlSTATE[07002]: COUNT field incorrect: 0 [Microsoft][ODBC sql Server Driver]COUNT field incorrect or Syntax error (sqlExecute[0] at ext\pdo_odbc\odbc_stmt.c:259) (sql: select * from information_schema.tables where table_schema = migrations and table_name = ?)

  at C:\inetpub\wwwroot\Fleet\vendor\laravel\framework\src\Illuminate\Database\Connection.PHP:678
    674▕         // If an exception occurs when attempting to run a query,we''ll format the error
    675▕         // message to include the bindings with sql,which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database''s errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query,$this->prepareBindings($bindings),$e
    680▕             );
    681▕         }
    682▕

我以前从未在 PHP 上看到过此错误,并且在 SO 或 Google 上找不到任何有用的信息。

我已经尝试将连接驱动程序更改为所有可能的,但我可以使用 DB::select 手动连接,但我无法创建所需的表、视图或架构。

有没有人以前见过这个错误并且可以帮助修复它/为我指明正确的方向。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Laravel

Laravel "PHP Artisan route:list" 失败,目标类 [AppHttpControllersAPIAuthLoginController] 不存在

如何解决Laravel "PHP Artisan route:list" 失败,目标类 [App\Http\Controllers\API\Auth\LoginController] 不存在?

执行命令“PHP artisan route:list”时如果收到此消息:

   Illuminate\Contracts\Container\BindingResolutionException  : Target class [App\Http\Controllers\API\Auth\LoginController] does not exist.

  at /mnt/c/Sources/wachtweken.nl/vendor/laravel/framework/src/Illuminate/Container/Container.PHP:805
    801|
    802|         try {
    803|             $reflector = new ReflectionClass($concrete);
    804|         } catch (ReflectionException $e) {
  > 805|             throw new BindingResolutionException("Target class [$concrete] does not exist.",$e);
    806|         }
    807|
    808|         // If the type is not instantiable,the developer is attempting to resolve
    809|         // an abstract type such as an Interface or Abstract Class and there is

  Exception trace:

  1   Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}()
      [internal]:0

  2   ReflectionException::("Class App\Http\Controllers\API\Auth\LoginController does not exist")
      /mnt/c/Sources/wachtweken.nl/vendor/laravel/framework/src/Illuminate/Container/Container.PHP:803

我了解到系统在 App\Http\Controllers\API\Auth\LoginController 中找不到类 因为它位于 App\Http\Controllers\Auth\LoginController

他从哪里获取存储在 App\Http\Controllers\API\Auth\LoginController 中的信息?

很多主题都将“PHP artisan config:cache”作为解决方案,但这不起作用

解决方法

我注意到在 web.php 的 API 命名空间中有一行:

Route::get(''logout'',''Auth\LoginController@logout'');

那不应该在那里。这解决了错误。

Laravel 5.0 php artisan make:model ModelName自动创建迁移类

Laravel 5.0 php artisan make:model ModelName自动创建迁移类

Laravel的命令:
PHP artisan make:model ModelName

使用“模型名称”自动创建创建迁移类.是否有办法可以将其他参数传递给make:model命令,以便忽略创建迁移类?

你应该写这个命令:
PHP artisan make:model modelName –no-migration

Artisan CLI为所有命令提供帮助消息.
例如,PHP artisan help make:model显示make:model命令的可用cli参数列表.

更新[2015]:从5.1开始,不再自动创建迁移.您可以使用标志–migration生成一个.

今天的关于Laravel框架学习 -- php artisan down/upphp laravel框架 新手教程的分享已经结束,谢谢您的关注,如果想了解更多关于c# – async as down down issue、IlluminateDatabaseQueryException SQLSTATE[07002] 在任何开发之前运行 php artisan migrate 后出错、Laravel "PHP Artisan route:list" 失败,目标类 [AppHttpControllersAPIAuthLoginController] 不存在、Laravel 5.0 php artisan make:model ModelName自动创建迁移类的相关知识,请在本站进行查询。

本文标签: