Category Archives: PHP

[Solved] getObject: FAILED RequestCoreException: cURL resource: Resource id #78; cURL error: SSL certificate

Reason:

The reason for this problem is that curl.cainfo is not configured, which is located in php.ini.

Solution:

Since the reasons for the errors are stated, it is much easier to solve them, as follows:

1. Download cacert

Download address: https://curl.haxx.se/ca/cacert.pem

2. Modify php.ini and restart

curl.cainfo="real_path/cacert.pem"

matters needing attention:

Needs to be turned on php_curl、php_openSSL extension;

PHP file download, download failed, nginx open() nginx / fastcgi_ temp/2/10/0000000102“ failed (13: Permission denied)

summary

The file download failed when testing the project

Check the problem

After investigation, it is found that nginx gives error information
open() "/ home/server/nginx/fastcgi_ Temp/2/10/0000000102 "failed (13: permission denied) while reading upstream
nginx prompts us that we do not have permission to operate

and then we enter the directory /home/server/nginx to check fastcgi_ Temp file owner, our name is the root user of root group

we will check the user group and user name of nginx worker again

ps -ef | grep nginx
# We can see that the worker process of nginx is the www user
root 80246 1 0 10:37 ?       00:00:00 nginx: master process /home/server/nginx/sbin/nginx
www 80247 80246 0 10:37 ?       00:00:00 nginx: worker process
root 82877 82840 0 13:56 pts/7 00:00:00 grep --color=auto nginx
# View the group that the www user is in, and the members of the group
groups www
# Ours is the www user of the www user group
www:www

solve the problem

When we download, the nginx worker process is sending the fastcgi_ Temp does not have permission to write to the cache
so we just need to give fastcgi_ The start-up user with the permission of nginx to modify the temp directory WWW: www

chown -R www:www fastcgi_temp/

Undefined index: name error in composer [How to Solve]

I made this mistake when:

Laravel version 5.8, need to introduce tcpdf, in the run

composer require tecnickcom/tcpdf

I found two answers, both of which were caused by the composer upgrade, but I don’t remember that I was promoted. I learned from one of the methods and successfully introduced the tcpdf extension. Now I integrate the two methods:

1. Change the source code

Positioning error:

vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php

122 line prompt does not have the key name, according to the code prompt to find

/vendor/laravel/framework/src/Illuminate/Support/Collection.php

Of   Mapwithkeys method. Add a compatible method to cover the original method

 public function mapWithKeys(callable $callback)
    {
        $result = [];
        $item = $this->items;
        if(isset($item['packages'])){
            $item = $item['packages'];
        }
        foreach ($item as $key => $value) {
            $assoc = $callback($value, $key);
 
            foreach ($assoc as $mapKey => $mapValue) {
                $result[$mapKey] = $mapValue;
            }
        }
 
        return new static($result);
    }

2. Composer level

# composer Downgrade (if you can't downgrade, you can try to run with root privileges)
composer self-update --1
 
# Re-install and It's Done!!!
composer install 

The above two methods are effective

[Solved] Git error: You have not concluded your merge (MERGE_HEAD exists)

Enter the root directory of the website

Solution 1: keep the local changes and stop merging – & gt; Re merge – & gt; Pull again

$:git merge --abort
$:git reset --merge
$:git pull

Solution 2: discard the local code, and the remote version will cover the local version (be careful)

$:git fetch --all           //Repulling
$:git reset --hard origin/master //git reset --hard reverts master back to origin/master and ignores all new commits
$:git fetch

[Solved] has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check: No

Has been blocked by CORS policy: response to preflight request doesn’t pass access control check: no ‘access control allow origin’ header is present on the requested resource.
seeing this error in the webpage, I know that it must be a cross domain problem of Ajax requests.
there are two solutions to this problem, as you should know after reading my article, Before I sent the front-end solution, I don’t know how to flip through my article list
today we talk about the server-side solution
add this code before the JSON data to be returned:


// Specify to allow access to other domains
header('Access-Control-Allow-Origin:*');
// Response type
header('Access-Control-Allow-Methods:POST');
// response header settings
header('Access-Control-Allow-Headers:x-requested-with,content-type');

Here is the PHP code, you can also change it to the corresponding java code.

[Solved] PhpSpreadsheet Error: Invalid cell coordinate [1

When TP5 uses phpspreadsheet, if the number of columns exceeds 26, it will report an error. The specific solutions are as follows: it is easy to use by personal test

//Write to the table header section to read
  // Set the table header
  // $head formatted as ['Name', 'Phone', 'Contact']
        $colum = 'A';
        foreach ($head as $v) {
            $sheet->setCellValue($colum . '1', $v);
            $sheet->getColumnDimension($colum)->setWidth(20);
            $colum++;
        }
        //Write content to read
          $column = 2;
        foreach ($data as $key => $rows) {
            $span = 'A';
            // Column Write
            foreach ($rows as $keyName => $value) {
                $sheet->setCellValue($span . $column, $value);
                $span++;
            }
            $column++;
        }

PHP encryption 3DES error Call to undefined function: mcrypt_module_open() solution

$td = mcrypt_module_open( MCRYPT_3DES,”, MCRYPT_MODE_CBC,”); It is him who reported the error.

I searched a lot of solutions, the correct method should be (only for windows system):

 

This error occurs when the function mcrypt_module_open is used for decryption when the server running php lacks libmcrypt.dll.
Do the following settings on the server to solve the problem.

 

Download a php mcrypt module installation package from the Internet, you only need the libmcrypt.dll file (generally downloaded from the official website, there is already in the php directory)

 

1. Copy libmcrypt.dll to the system32 directory or the extensions directory under the php installation directory
2. Copy libmcrypt.dll to the bin directory of the apache installation directory
3. Find the php.ini file in the windows directory and open it
4. Find; Directory in which the loadable extensions (modules) reside.
extension_dir = “./”  such as: extension_dir = “D:\php5\ext”
these two lines, make sure that libmcrypt.dll can be found in the directory pointed to by extension_dir, or the system There is libmcrypt.dll under path
5. Find; under the Windows Extensions item; extension=php_mcrypt.dll this line and ;extension=php_iconv.dll (mine is not, omitted) these two lines, remove the front semicolon

How to Solve opcache error: zend_mm_heap corrupted

There are always problems with production. It seems that the memory is full, which makes it impossible to request

situation:

1. Machine clusters are built with containers
2. The request always appears 502, and it will appear after restarting PHP FPM

3. Open the error log configuration

Of course, you can’t turn off opcache directly. You will find that there is no cache. The memory is very high

Open the error log, and the log will appear in/var/log/PHP FPM/error.log

VI/etc/php-fpm.d/w8002.conf # select different conf files according to which group you want to change
Add a line at the end: catch_ workers_ output = yes

Php5.6 has been reported Zend_ mm_ Heap corrupted with standard PHP 5.6: locating the cause and “Zend”_ mm_ “Heap corrupted” looks like a memory explosion. After a turn, it’s the problem of opcache. Try to disable it, modify the configuration in php.ini and restart PHP FPM

View PHP error log

[root@ip php-fpm]# grep zend error.log | tail -n 3
[01-Jun-2021 00:21:01] WARNING: [pool www8002] child 20812 said into stderr: "zend_mm_heap corrupted"
[01-Jun-2021 00:27:49] WARNING: [pool www8002] child 32582 said into stderr: "zend_mm_heap corrupted"
[01-Jun-2021 00:28:06] WARNING: [pool www8002] child 339 said into stderr: "zend_mm_heap corrupted"

cat php.ini | grep "opcache"
1. /etc/php.d/opcache.ini 改 "opcache.enable=0"
2. systemctl restart php-fpm

Key point: of course, you can’t turn off opcache directly. You will find that the cache memory is too high, so you can’t turn off opcache directly. Let’s start tuning opcache

; switch on
opcache.enable=1

; available memory, as appropriate, in megabytes
opcache.memory_consumption=256

Maximum number of files to cache, try to increase this value if the hit rate is less than 100%
opcache.max_accelerated_files=5000

opcache.max_accelerated_files=5000 ; Opcache will check the modification time of files within a certain period of time, here set the check time period, the default is 2, in seconds
opcache.revalidate_freq=240

The memory size of the interned string, also adjustable
opcache.interned_strings_buffer=8   

whether to fast shutdown, the speed of reclaiming memory will be increased when PHP Request Shutdown is turned on
opcache.fast_shutdown=1

Do not save file/function comments
opcache.save_comments=0

Reference Links:
1.https://stackoverflow.com/questions/2247977/what-does-zend-mm-heap-corrupted-mean
2.https://stackoverflow.com/questions/50769286/zend-mm-heap-corrupted-with-standard-php-5-6-locating-the-cause

[Solved] Request exceeded the limit of 10 internal redirects due to possible configuration error

//httpd error log error:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase 
the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://127.0.0.1/MyProject/login/userLogin

Most of the answers on the Internet are about. Htaccess, but I don’t think there’s anything wrong with local HTaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond   %{REQUEST_FILENAME} !-f
    RewriteRule   ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ apg/public/    [L]
    RewriteRule  (.*) apg/public/$1 [L]
</IfModule>

The url is correct

http://127.0.0.1/MyProject/login/userLogin

But the page doesn’t display the right content.
Let me see where the framework needs to be changed. I still think the framework hasn’t changed.
Solutions:
Later, I checked my collection.php, and there was an array in it, and I added the name of MyProject MyProject:

 static private $ProjectsArray = array(
            'project1',
            'project2',
            'project3',
            'MyProject'
);

The problem solved! Check my localhost page again and you can visit my Project login page. The framework has been set up successfully!