Category Archives: PHP

Laravel-admin php artisan admin:install error reporting problem solution

Problem description: According to the installation steps of the official laravel-admin document, execute: php artisan admin:install An error was reported during installation.

In fact, the problem of creating special characters in the database is too long. Laravel 5.4 changed the default database character set. Now utf8mb4 includes support for storing emojis. If you are running MySQL v5.7.7 or higher, you don’t need to do anything.

When you try to run the migrations command on some MariaDB or some older versions of MySQL, you may encounter the following error:

D:\wwwroot\www.test.com>php artisan admin:install
Migration table created successfully.

In Connection.php line 664:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (S
  QL: alter table `users` add unique `users_email_unique`(`email`))


In Connection.php line 458:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

The solution is to add default values ​​in app\Providers\AppServiceProvider.php, and you need to delete the database migrations and users tables. Re-execute: php artisan admin:install

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; //add fixed sql

class AppServiceProvider extends ServiceProvider
{
    /* *
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191); //add fixed sql
    }

    /* *
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
     }
}

Workman Run Error: stream_socket_server() has been disabled for security reasons

Start the workman and report an error

Workerman[start.php] start in DEBUG mode
stream_socket_server() has been disabled for security reasons in file /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php on line 2214
PHP Fatal error:  Uncaught Exception in /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php:2216
Stack trace:
#0 /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php(646): Workerman\Worker->listen()
#1 /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php(504): Workerman\Worker::initWorkers()
#2 /home/wwwroot/laykefu/vendor/workerman/Config/start.php(37): Workerman\Worker::runAll()
#3 {main}
  thrown in /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php on line 2216

Fatal error: Uncaught Exception in /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php:2216
Stack trace:
#0 /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php(646): Workerman\Worker->listen()
#1 /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php(504): Workerman\Worker::initWorkers()
#2 /home/wwwroot/laykefu/vendor/workerman/Config/start.php(37): Workerman\Worker::runAll()
#3 {main}
  thrown in /home/wwwroot/laykefu/vendor/workerman/workerman/Worker.php on line 2216

The reason is: PHP the stream_socket_erver()function is disabled

Solution

Find the php.inifile and find disable_functionswhether stream_socket_server()this function is disabled in this item

find / -name php.ini # Find the location of php.ini
vim /usr/local/php/etc/php.ini # open edit php.ini

Press esc key, enter :/stream_socket_server, press nstart search

Check the function is not in disable_functionsthis one there, this one is meant Prohibited Method

If there is this function, delete it, press the esc key, enter to wqsave and exit

Restart php-fpm

service php-fpm restart

Mac installs the php Swoole extension and appears Enable openssl support, require openssl library or fatal error:’openssl/ssl.h’ file not found

When installing php Swoole extend Mac Enable openssl support, require openssl libraryor fatal error: 'openssl/ssl.h' file not foundwhen specifying the opensslpath just fine

./configure --with-openssl-dir=/usr/local/opt/openssl@1.1 --enable-http2 --with-php-config=/Applications/MAMP/bin/php/php7.4.2/bin/php-config

The OpenSSL installed by brew is by default /usr/local/Cellar/openss/version, and I will report fatal error: 'openssl/ssl.h' file not foundan error after using it . Probably my openssl installation path is in/usr/local/opt/[email protected]

PHP solves the problem that composer exceeds the memory size Allowed memory size

Preface

Today, when I used composer to update and install the expansion pack, it reported that the memory size was exceeded

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Rule2Literals.php on li
ne 53

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.

Solution

First execute the composer help command to obtain the composer installation directory

composer -h

Results of the

D:\php_work\fund-admin>composer -h
Usage:
  help [options] [--] [<command_name>]

Arguments:
  command                        The command to execute
  command_name                   The command name [default: "help"]

Options:
      --xml                      To output help as XML
      --format=FORMAT            The output format (txt, xml, json, or md) [default: "txt"]
      --raw                      To output raw command help
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  The help command displays help for a given command:

    php C:\ProgramData\ComposerSetup\bin\composer.phar help list

  You can also output the help in other formats by using the --format option:

    php C:\ProgramData\ComposerSetup\bin\composer.phar help --format=xml list

  To display the list of available commands, please use the list command.

I can see C:\ProgramData\ComposerSetup\bin\composer.pharmy composer installation directory

At this time, the installation extension command is modified to

# php -d memory_limit=-1 php program set memory unlimited
# C:\ProgramData\ComposerSetup\bin\composer.phar composer install url
# require dcat/laravel-admin:"2.*" -vvv Loading expansion packs
php -d memory_limit=-1 C:\ProgramData\ComposerSetup\bin\composer.phar require dcat/laravel-admin:"2.*" -vvv

[PHP] Array to string conversion error when sending data in post

When using curl to pass post data, if the data field is an array, an error will be reported Array to string conversion

When calling curl_setopt_array($curl, $options);

Call curl_setopt($ch, CURLOPT_POSTFIELDS, $data)

Errors may be reported in these two places, the solution is to process the data array

http_build_query($data)

How to Solve PHP Error: no package’oniguruma’ found

When compiling and installing php, if –enable-mbstring, the mbstring extension is enabled, this regular processing library is required

 

centos

yum install http: // rpms.remirepo.net/enterprise/7/remi/x86_64 // oniguruma5-6.9.4-1.el7.remi.x86_64.rpm 
yum install http: // rpms.remirepo.net/enterprise/ 7/remi/x86_64 // oniguruma5-devel-6.9.4-1.el7.remi.x86_64.rpm

ubuntu

apt install libonig-dev

[PHP] php8 jit does not support 32-bit systems WARNING: JIT not supported by host architecture

The jit of php8 needs to be manually turned on when compiling the opcache extension

For example, my php8 source code directory is here:

/home/ubuntu/myphp/php-8.0.0alpha1/ext/opcache

carried out

./configure –enable-opcache-jit –with-php-config=/usr/local/php8/bin/php-config

There will be a warning

WARNING: JIT not supported by host architecture

 

View configuer script

 

 x86_64 only works, the others will be detected but

[PHP] __autoload function will be called when class_exists does not exist

The definition of this function is as follows:

class_exists ( string $class_name [, bool $autoload = true ]): bool

The second parameter is whether to automatically call the autoload function

class_name 
class name. The matching of names is not partition case. 
Whether 

autoload calls __autoload by default.

Of course, it is now recommended to use the following function for automatic loading

spl_autoload_register(function ($class_name) { 
    require_once $class_name. ' .php ' ; 
});

If you don’t want to call, give false as the second parameter