Answer the question
In order to leave comments, you need to log in
Why is the script for adding products not being executed completely?
Hello. I have written code to add items to WC.
In the script, I include wp-load.php and use the WP and WC functions to do this.
And I ran into such a problem that the script adds n-products and then just turns off (I run php script.php through the console).
There are no errors in the console, nothing appears in the wp logs either.
At the same time, as it is executed, according to the idea, it should write the start time, the addition log and the end time in the console.
But at the same time, the console is empty, and upon completion (departure), it immediately displays all the lines that it should have displayed as it was being executed.
Where to dig?
Answer the question
In order to leave comments, you need to log in
Perhaps the command execution timeout is triggered, for this the following directives max_execution_time are used (the default value is usually 30 seconds), to change the value, the following line must be added at the beginning of the script:
ini_set('max_execution_time', 600); // thus the script will have an execution timeout of 600 seconds
Also, the allocated memory limit can affect the execution of the script, for this the memory_limit
1 directive is used. The PHP that you use in the console and the PHP that is used on your site may be different.
In order to fix your problem you need:
Change the max_execution_time and memory_limit parameters up for the version of PHP your site is running on! Not for PHP console version. The following describes how to do this:
1. Check the current max_execution_time and memory_limit settings. To do this, go to the root of the site. Create a file with any name, for example myinfo.php and add the code there:
<?php
phpinfo();
Save the file and open the file in a browser: xn--_-7sbbf2b7bj7b/myinfo.php
In the window that opens, find the values of the max_execution_time and memory_limit parameters.
2. Change the parameters max_execution_time and memory_limit:
Depends on the platform where your site is running. We recommend changing the settings in the following ways:
Method No. 1 - .user.ini
- Create a .user.ini file in the root of the site and enter the parameters you need. Example:
max_execution_time=600
memory_limit=800M
Refresh the page xn--_-7sbbf2b7bj7b/myinfo.php to make sure that the settings have changed
Method #2 - .htaccess
In the .htaccess file
- Create an .htaccess file in the root of the site and enter the settings you need. Example:
php_value max_execution_time 600
php_value memory_limit 800M
Refresh the xn--_-7sbbf2b7bj7b/myinfo.php page to make sure the parameters have changed
Method #3 - In the php configuration of the control panel You probably
have a hosting control panel installed.
In the PHP settings, you can most often set the desired parameters.
If you encounter difficulties, contact your hosting company and ask for support in this matter or instructions on how to change settings.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question