define( ‘WP_DEBUG’, false );
再wp-config.php 配置这两个值可以在也买你上输出debug信息
define( ‘WP_DEBUG’, false );
再wp-config.php 配置这两个值可以在也买你上输出debug信息
要执行请求的操作,wordPress需要访问您网页服务器的权限。 请输入您的FTP登录凭据以继续。 如果您忘记了您的登录凭据(如用户名、密码),请联系您的主机提供商
sudo chown -R www-data /var/www/wordpress
sudo chmod -R 775 /var/www/wordpress
修改wordpress目录拥有者为www-data
server {
listen 8080;
server_name laravel.localhost;
client_max_body_size 10M;
# Load configuration files for the default server block.
location / {
root D://robin-admin/public;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
root D://robin-admin/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
nginx 根目录指向laravel 的下的public 文件夹
try_files $uri $uri/ /index.php?$query_string; 可以有效重新访问后缀(不需要显式指明php后缀)
今天,我们将通过介绍 Laravel 中一个不太为人所知的功能,来展示如何快捷的调试数据库中的数据。通过使用 Laravel artisan 内建的 php artisan tinker
, 我们可以很方便的看到数据库中的数据并且执行各种想要的操作。
Laravel artisan 的 tinker 是一个 REPL (read-eval-print-loop),REPL 是指交互式命令行界面,它可以让你输入一段代码去执行,并把执行结果直接打印到命令行界面里。
// see the count of all users
App\User::count();
// find a specific user and see their attributes
App\User::where('username', 'samuel')->first();
// find the relationships of a user
$user = App\User::with('posts')->first();
$user->posts;
factory(App\User::class, 10)->create();
App\User::all();
App\User::count();
$user = new App\User;
$user->name = "Wruce Bayne";
$user->email = "iambatman@savegotham.com";
$user->save();
doc XXX
查阅某个方法的文档
show XXX
显示某个方法的代码
laravel 的form 对象 有magic方法 可以快速添加表单项
/**
* Class Form.
*
* @method Field\Text text($name, $label = '')
* @method Field\Password password($name, $label = '')
* @method Field\Checkbox checkbox($name, $label = '')
* @method Field\CheckboxButton checkboxButton($name, $label = '')
* @method Field\CheckboxCard checkboxCard($name, $label = '')
* @method Field\Radio radio($name, $label = '')
* @method Field\RadioButton radioButton($name, $label = '')
* @method Field\RadioCard radioCard($name, $label = '')
* @method Field\Select select($name, $label = '')
* @method Field\MultipleSelect multipleSelect($name, $label = '')
* @method Field\Textarea textarea($name, $label = '')
* @method Field\Hidden hidden($name, $label = '')
* @method Field\Id id($name, $label = '')
* @method Field\Ip ip($name, $label = '')
* @method Field\Url url($name, $label = '')
* @method Field\Color color($name, $label = '')
* @method Field\Email email($name, $label = '')
* @method Field\Mobile mobile($name, $label = '')
* @method Field\Slider slider($name, $label = '')
* @method Field\File file($name, $label = '')
* @method Field\Image image($name, $label = '')
* @method Field\Date date($name, $label = '')
* @method Field\Datetime datetime($name, $label = '')
* @method Field\Time time($name, $label = '')
* @method Field\Year year($column, $label = '')
* @method Field\Month month($column, $label = '')
* @method Field\DateRange dateRange($start, $end, $label = '')
* @method Field\DateTimeRange dateTimeRange($start, $end, $label = '')
* @method Field\TimeRange timeRange($start, $end, $label = '')
* @method Field\Number number($name, $label = '')
* @method Field\Currency currency($name, $label = '')
* @method Field\SwitchField switch($name, $label = '')
* @method Field\Display display($name, $label = '')
* @method Field\Rate rate($name, $label = '')
* @method Field\Divider divider($title = '')
* @method Field\Decimal decimal($column, $label = '')
* @method Field\Html html($html)
* @method Field\Tags tags($column, $label = '')
* @method Field\Icon icon($column, $label = '')
* @method Field\Captcha captcha($column, $label = '')
* @method Field\Listbox listbox($column, $label = '')
* @method Field\Table table($column, $label, $builder)
* @method Field\Timezone timezone($column, $label = '')
* @method Field\KeyValue keyValue($column, $label = '')
* @method Field\ListField list($column, $label = '')
* @method mixed handle(Request $request)
*/
真实调用的方法
/**
* Generate a Field object and add to form builder if Field exists.
*
* @param string $method
* @param array $arguments
*
* @return Field|$this
*/
public function __call($method, $arguments)
{
if (!$this->hasField($method)) {
return $this;
}
$class = BaseForm::$availableFields[$method];
$field = new $class(Arr::get($arguments, 0), array_slice($arguments, 1));
return tap($field, function ($field) {
$this->pushField($field);
});
}
__call 属于php 类对象的magic 方法
当调用一个不存在与类定义的方法 就会 在call中调用
function __call($name,$arguments) {
}
$name 为方法名字
$argument 为方法参数
使用laravel 的数据库Facade 可以比较好的 执行数据库sql
$array = DB::select("select * from admin_users");
//raw 执行sql
$object = DB::table("admin_users")->where("id","=","1")->first();
//获取查询第一条
$array = DB::table("admin_users")->where("id","=","1")->get();
//
get获取数据列表
$array = DB::table("admin_users")->where("id","=","1")->skip(0)->take(1)->get();
//分页查询
$array = DB::table("admin_users")->where("id","=","1")->skip(0)->limit(1)->get();
//分页查询
DB::transaction(function (){
//内部执行开启事务
});
//手动控制事务
DB::beginTransaction();
DB::commit();
DB::rollBack();
php socket 第三方库 composer require react/socket
该库针对 socket / 流 做事件监听(应该是epoll )主线程做事件循环 (reactive)所以该reactive 框架貌似只能在 linux下使用
server
<?php
require '../vendor/autoload.php';
echo "enter script\n";
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server('127.0.0.1:8080', $loop);
$socket->on('connection', function (React\Socket\ConnectionInterface $connection) {
echo "" . $connection->getRemoteAddress() . "client connected\n";
$connection->write("Hello " . $connection->getRemoteAddress() . "!\n");
$connection->write("Welcome to this amazing server!\n");
$connection->write("Here's a tip: don't say anything.\n");
$connection->on('data', function ($data) use ($connection) {
echo "" . $data . "\n";
//$connection->close();
});
});
echo "server started at 8080\n";
$loop->run();
其中$loop 就是事件循环对象
client
<?php
require '../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$connector = new React\Socket\Connector($loop);
$connector->connect('127.0.0.1:8080')->then(function (React\Socket\ConnectionInterface $connection) use ($loop) {
echo "client connected\n";
$connection->write("Hello World!\n");
$connection->on('data', function ($data) use ($loop, $connection) {
echo "" . $data . "\n";
//$connection->close();
//$output = new React\Stream\WritableResourceStream(fopen("./client.txt", "w"),$loop);
//$output = fopen("./client.txt", "w");
//fwrite($output,$data);
//$output->write("" . $data . "\n");
while($input = fgets(STDIN, 10))
{
echo $input."\n";
$connection->write($input);
}
});
/*
$input = new React\Stream\ReadableResourceStream(STDIN,$loop);
$input->on("data",function ($data) use ($connection) {
$connection->write($data);
});*/
//$output = fopen("./client.txt", "w");
//$steam = new React\Stream\WritableResourceStream($output,$loop);
//$connection->pipe($steam);
});
$loop->run();
最亮眼的是 将文件描述符(标准输出流 文件输出流)fd 包装成一个响应式流对象 通过pipe实现管道功能 而且生命周期相同 会同时关闭。
composer设置阿里云镜像源
composer config -g secure-http false
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
composer config -g -l
composer config -g -l
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https://mirrors.aliyun.com/composer/
php 通过 symfony/http-foundation(http请求响应封装) 框架捕获http请求
laravel kernel 类 为laravel http 入口
middleware 类似于 过滤器 可以执行请求处理 然后next 执行处理链 必定有 handle 方法 当需要处理请求前操作 在调用 $next 前修改请求信息 当需要处理请求后 或者 在响应上操作 则 在$next后 修改信息 且返回结果必定为 $response对象
public function handle($request, Closure $next)
{
// Check if we're dealing with CORS and if we should handle it
if (! $this->shouldRun($request)) {
return $next($request);
}
// For Preflight, return the Preflight response
if ($this->cors->isPreflightRequest($request)) {
$response = $this->cors->handlePreflightRequest($request);
$this->cors->varyHeader($response, 'Access-Control-Request-Method');
return $response;
}
// Add the headers on the Request Handled event as fallback in case of exceptions
if (class_exists(RequestHandled::class) && $this->container->bound('events')) {
$this->container->make('events')->listen(RequestHandled::class, function (RequestHandled $event) {
$this->addHeaders($event->request, $event->response);
});
}
// Handle the request
$response = $next($request);
if ($request->getMethod() === 'OPTIONS') {
$this->cors->varyHeader($response, 'Access-Control-Request-Method');
}
return $this->addHeaders($request, $response);
}