In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the reasons for the shell script as a daemon to ensure that the PHP script does not hang up". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what are the reasons for the shell script as a daemon to ensure that the PHP script does not hang up.
Here's what I'm dealing with:
1. Save the 2000w list to the temporary data table
2. Use the PHP program to get 500 users from the table at a time, and generate the original SQL update record after detection.
3. In order to prevent the PHP program from being cut off suddenly, use the shell script to check every 1 minute. If the PHP is dead, restart it.
The reason I use the shell script as the daemon is that the detection interface between the phone and the mailbox is slow, and it is impossible to detect 2000w users in 1-2 days.
Details of the plan:
1. Temporarily save the user list table users, which is structured as follows:
The copy code is as follows:
CREATE TABLE `users` (
`roomt`varchar (50) COMMENT 'username'
`Phone`tinyint (3) unsigned NOT NULL default'0' COMMENT 'whether you have a cell phone number'
`has_ email`tinyint (3) unsigned NOT NULL default'0' COMMENT 'whether there is a mailbox'
``tinyint (3) unsigned NOT NULL default'0' COMMENT 'flag bit'
PRIMARY KEY (`roomt`)
KEY `room` (`room`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=' list list'
I first import the 2000-odd user name into this temporary table. The default fields of has_phone and has_email are 0 (none), and the flag bit flag indicates whether the user has been detected.
Here is a portion of the table data:
9873aaa,0,0,0
Adddwwwd876222,0,0,0
Testalexlee,0,0,0
Codejia.net,0,0,0
Haohdouywaa21,0,0,0
2. PHP script check_users.php
After importing the user list into the table, write a simple PHP script that goes like this: each cycle fetches the 500users of flag=0 from the table, then requests the API to determine whether the user has a mobile phone number and mailbox, generates a SQL, saves it in a SQLS array, and so on, loops the SQLS array, updates the 500list in the table, and sets the flag flag bit to 1, indicating that the detection has been completed. I won't get it next time.
Because the PHP script code is long, here is a simple code description:
The copy code is as follows:
The above is a concise version of the PHP script, which probably means that the initial version does not have the variable $total_nums, because at the beginning of running this script, I found that I only ran more than 4w scripts and then hung the ball. Later, it was because the connection database was not connected, and the script was hanging there all the time. Adding this variable won't solve the problem, but after running 1w users at a time, the PHP script exits and is restarted by the following shell script.
3. Shell script as daemon
I added this shell script to the crontab and executed it every 1 minute. The shell script is very simple to detect whether there is a process id in check_users.php. If it exists, it means that the PHP script is still running and the shell script does not do anything; if it does not exist, it means that the PHP script has finished exit (0) and the user has exited, then the shell script starts the script and enters the detection of the next 1w user list.
As I mentioned above, if the PHP script is unable to connect to the database, the PHP will hang the ball there all the time and cannot exit. I added a time test in the shell script to calculate how long the PHP script process has existed, and if it exceeds the time I expected, kill the PHP script and restart it.
At the beginning of the example data, the results are similar to the following:
Testalexlee,1,0,1
Codejia.net,0,0,1
Haohdouywaa21,1,1,1
9873aaa,0,1,1
Adddwwwd876222,1,0,1
Thank you for your reading, these are the contents of "what are the reasons for shell scripts as daemons to ensure that PHP scripts do not hang up?" after the study of this article, I believe you have a deeper understanding of what the reasons for shell scripts as daemons to ensure that PHP scripts do not hang up, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.