Explorar el Código

php的Dockerfile新添加xdebug扩展

chenlong hace 4 años
padre
commit
51b7d70fe6

+ 3 - 2
Dockerfile

@@ -30,9 +30,10 @@ deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
     && pecl install memcached-3.1.4 \
     && pecl install redis-5.2.2 \
     && pecl install imagick mcrypt zip swoole \
-    && docker-php-ext-enable memcached redis imagick mcrypt zip swoole
+    && pecl install xdebug \
+    && docker-php-ext-enable memcached redis imagick mcrypt zip swoole xdebug
 
 # 镜像信息
 LABEL Author="vance"
-LABEL Version="2020.8"
+LABEL Version="2021.3"
 LABEL Description="PHP 7.4 开发环境镜像."

+ 216 - 0
app/Http/Controllers/TestController.php

@@ -0,0 +1,216 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class TestController extends Controller
+{
+    public function index(){
+//        //dd($this->testMaxLengthStr('abcabcbb'));
+//        //dd($this->quickSort([2,3,1,3,5,2]));
+//        dd($this->binLoop([1,2,3,4,5],2));
+//        //dd($this->testArray());
+//        dd($this->binary_search([1,2,3,4,5],5));
+//        $arr = [1,2,3,4,5];
+//        dd($this->binary_search_recursion($arr,2, 0, count($arr)));
+
+        $a = 6;
+        xdebug_debug_zval('a');
+        $b = $a;
+        xdebug_debug_zval('a');
+        unset($b);
+        xdebug_debug_zval('a');
+    }
+
+    public function testArray(){
+        $a = array(1,2,5,6);
+        $b = array(1,2,7);
+//        $a=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
+//        $b=array("a"=>"purple","b"=>"orange");
+        //var_dump(array_combine($a,$b)); //将$a中的value作为$b中对应的key,元素个数必须一致。
+        //var_dump(range(2,6));  //[2,3,4,5,6]
+//        $firstname = "Peter";
+//        $lastname = "Griffin";
+//        $age = "41";
+        //return compact("firstname", "lastname", "age");  //变量作为key ["firstname" => "Peter","lastname"=> "Griffin","age"=>"41"]
+        //return array_chunk($b,1);  //以最大长度分割数组
+        //return array_merge($a,$b);   //合并
+        return array_merge_recursive();  //合并 如果数组中有完全一样的键,将它们递归合并
+        //return array_slice($b,0,1,false);//截取
+        //return array_diff($a,$b);  //a相对于b的差值  [2=>5,3=>6]
+       // return array_intersect($a,$b); //交集
+        //return array_search(0,$a);//返回key  false
+//        array_splice($a,0,2,$b);  //移除$a中元素 用$b替换
+//        return $a;
+
+        //return array_key_exists(20,$a);
+
+//        shuffle($a);   //随机打乱数组
+//        return $a;
+
+//        return array_flip($a);  //交换数组的键值 返回新数组
+//        array_reverse(); //倒序
+//        array_unique();//去重
+    }
+
+    /**
+     * 截取一个字符串最大长度不重复段,且返回该字符串段及其长度
+     * 例:'abcadcagc' 输出:'abc' 长度为3
+     */
+    public function testMaxLengthStr($str){
+        $current = '';
+        $max = 0;
+        $len=$i=0;
+        for(;$i<strlen($str);$i++){
+            if(strpos($current,$str[$i]) !== false){
+                $current = substr($current, strpos($current, $str[$i])+1);
+                $len = strlen($current);
+            }
+            $current .= $str[$i];
+            $len++;
+            $max = max($max, $len);
+        }
+        return $max;
+    }
+    /**
+     * 冒泡排序
+     * @param $arr
+     * @return mixed
+     */
+    public function bubbleSort($arr){
+        for($i = 0;$i < count($arr); $i++) {
+            for ($j = 0; $j < count($arr) - $i - 1; $j++) {
+                if ($arr[$j] > $arr[$j + 1]) {
+                    $temp = $arr[$j + 1];
+                    $arr[$j + 1] = $arr[$j];
+                    $arr[$j] = $temp;
+                }
+            }
+        }
+        return $arr;
+    }
+
+    /**
+     * 快速排序
+     * @param $arr [5,3,4,2,1,6,9,7,8]
+     * @return array
+     */
+    function quickSort($arr){
+        $count = count($arr);
+        if($count<=1){
+            return $arr;
+        }
+        $base_num = $arr[0];
+        $left_arr = array();
+        $right_arr = array();
+        for($i=1;$i<$count;$i++){
+            if($base_num > $arr[$i]){
+                $left_arr[] = $arr[$i];
+            }else{
+                $right_arr[] = $arr[$i];
+            }
+        }
+        $left_arr = $this->quickSort($left_arr);
+        $right_arr = $this->quickSort($right_arr);
+        return array_merge($left_arr,array($base_num),$right_arr);
+    }
+
+    /**
+     * 二分查找
+     * @param $arr
+     * @param $x
+     * @return false|int
+     */
+    function binLoop($arr,$x){
+        $start = 0;
+        $end = count($arr)-1;
+        while($start <= $end){
+            $middle = intval(($start+$end)/2); //[1,2,3,4,5] 5
+            if($arr[$middle]>$x){
+                $end = $middle-1;
+            }else if($arr[$middle]<$x){
+                $start = $middle+1;
+            }else{
+                return $middle;
+            }
+        }
+        return false;
+    }
+    /**
+     * 二分查找算法
+     * @param array $arr 待查找区间
+     * @param int $number 查找数
+     * @return int        返回找到的键
+     */
+    function binary_search($arr, $number) {
+        // 非数组或者数组为空,直接返回-1
+        if (!is_array($arr) || empty($arr)) {
+            return -1;
+        }
+        // 初始变量值
+        $len = count($arr);
+        $lower = 0;
+        $high = $len - 1;
+        // 最低点比最高点大就退出
+        while ($lower <= $high) {
+            // 以中间点作为参照点比较
+            $middle = intval(($lower + $high) / 2);
+            if ($arr[$middle] > $number) {
+                // 查找数比参照点小,舍去右边
+                $high = $middle - 1;
+            } else if ($arr[$middle] < $number) {
+                // 查找数比参照点大,舍去左边
+                $lower = $middle + 1;
+            } else {
+                // 查找数与参照点相等,则找到返回
+                return $middle;
+            }
+        }
+        // 未找到,返回-1
+        return -1;
+    }
+    /**
+     * @param array $arr 待查找区间
+     * @param int $number 查找数
+     * @param int $lower 区间最低点
+     * @param int $high 区间最高点
+     * @return int
+     */
+    function binary_search_recursion(&$arr, $number, $lower, $high) {
+        // 以区间的中间点作为参照点比较
+        $middle = intval(($lower + $high) / 2);
+        // 最低点比最高点大就退出
+        if ($lower > $high) {
+            return -1;
+        }
+        if ($number > $arr[$middle]) {
+            // 查找数比参照点大,舍去左边继续查找
+            return $this->binary_search_recursion($arr, $number, $middle + 1, $high);
+        } elseif ($number < $arr[$middle]) {
+            // 查找数比参照点小,舍去右边继续查找
+            return $this->binary_search_recursion($arr, $number, $lower, $middle - 1);
+        } else {
+            return $middle;
+        }
+    }
+
+    /**
+     * 含有中文字符 大小写转换
+     * @param $a
+     * @return string
+     */
+    function mystrtoupper($a){
+        $b = str_split($a, 1);
+        $r = '';
+        foreach($b as $v){
+            $v = ord($v);
+            if($v >= 97 && $v<= 122){
+                $v -= 32;
+            }
+            $r .= chr($v);
+        }
+        return $r;
+    }
+
+}

+ 35 - 0
app/Jobs/ProcessPodcast.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+
+class ProcessPodcast 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()
+    {
+        //
+    }
+}

+ 1 - 1
database/seeders/DatabaseSeeder.php

@@ -13,6 +13,6 @@ class DatabaseSeeder extends Seeder
      */
     public function run()
     {
-        // \App\Models\User::factory(10)->create();
+         \App\Models\User::factory(10000)->create();
     }
 }

+ 1 - 1
docker-compose.yml

@@ -1,7 +1,7 @@
 version: '3'
 services:
   redis-demo-php:
-    image: my-php-fpm:2020.8
+    image: my-php-fpm:2021.3
     container_name: "redis-demo-php"
     volumes:
       - ./:/www

+ 12 - 0
routes/web.php

@@ -3,6 +3,7 @@
 use Illuminate\Support\Facades\Route;
 use Illuminate\Support\Facades\Redis;
 use App\Http\Controllers\PostController;
+use App\Http\Controllers\TestController;
 /*
 |--------------------------------------------------------------------------
 | Web Routes
@@ -30,3 +31,14 @@ Route::get('/posts/popular', [PostController::class, 'popular']);
 Route::get('/posts/{post}', [PostController::class, 'show']);
 
 Route::get('/posts/{id}', [PostController::class, 'show'])->where('id', '[0-9]+');
+
+
+Route::get('/test', [TestController::class, 'index']);
+
+Route::get('/testdb', function () {
+    $user = \App\Models\User::where('name', '柳红')->first();
+    $user = \App\Models\User::where('name', '柳红')->first();
+    $user = \App\Models\User::where('name', '柳红')->first();
+    $user = \App\Models\User::where('name', '柳红')->first();
+    return view('welcome', ['user' => $user]);
+});