Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use php script to update product list regularly

Shulou Source: shulou.com Published: 2022-06-02 04:54:06 10月03日 Update

This article introduces the knowledge of "how to update the commodity list regularly with php script". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In order to improve the anti-concurrency ability in e-commerce projects, you need to cache the list of items. Here is the script used to update the cache:

/ / the temporary key//PRODUCTION where PRODUCTION_ is cached merchandise list is cached merchandise list key$con = mysqli_connect ($db_config ['host'], $db_config [' user'], $db_config ['passwd'], $db_config [' database']); $redis = new Redis (); $redis- > connect ($redis_config ['host']); $redis- > del (PRODUCTION_); $sql = "select * from production ORDER BY created_at"; $result = mysqli_query ($con,$sql); $artimages = [] While ($row = mysqli_fetch_assoc ($result)) {$redis- > lPush (PRODUCTION_,json_encode ($row));} / * * is not directly updated to the item list because the script takes a long time to execute when the amount of data in the item list is large. * after del PRODUCTION, users will not be able to read the product list when they visit the website before lPush PRODUCTION. * save the temporary list first, and then the rename is the key*/$redis- > rename (PRODUCTION_,PRODUCTION) of the actual query.

The appeal script is just a demo, which needs to be locked in the actual application, otherwise it will make an error when the script is not finished and the next automatic execution of crontab comes.

The following is the crontab script:

* root / usr/local/php/bin/php / xxx/xxxx/xxx/production.php > / dev/null 2 > & 1root is the user / usr/local/php/bin/php php script interpreter that executes the script. If you don't write the full path, you will get an error > / dev/null 2 > & 1 ignore the log output "how to use php script to update the product list regularly". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Script merchandise update cache actual time content situation more user knowledge website output practical successful learning and then just dilemma data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia OPPO Reno Redmi Apple