Answer the question
In order to leave comments, you need to log in
How can you optimize php code?
Hello, how can I optimize this code? As I understand it, the problem is in this line: $api_response = wp_remote_post($url_api , $params);
Mistake:
Fatal error: Maximum execution time of 30 seconds exceeded in A:\XAMP\htdocs\test\wp-includes\Requests\Transport\cURL.php on line 441
$arr_tovar = $result->products;
$url_api = $url_site.'/wp-json/wc/v3/products';
$params = [
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'admin:123123123' )
),
'body' => [],
];
foreach ($arr_tovar as $item) {
$params['body'] = array(
'name' => $item->name,
'status' => 'pending',
'id_iiko_rovara' => $item->productCategoryId,
'categories' => array(
array(
'id_iiko_категории' => $item->productCategoryId
)
),
'price' => $item->price
);
$api_response = wp_remote_post($url_api , $params);
$body = json_decode( $api_response['body'] );
if( wp_remote_retrieve_response_message( $api_response ) === 'Created' ) {
echo 'Этот продукт ' . $body->name . ' успешно создан <br>';
}else{
echo 'Ошибка';
}
}
Answer the question
In order to leave comments, you need to log in
no way, you need to increase the script execution time (execution_time) to 60 seconds in php.ini
There is such a thing as a queue of background processes. You can see here .
Woo, by the way, sits on it, i.e. among its files is this library.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question