


Linux uses crontab to implement PHP execution plan scheduled tasks_PHP tutorial
First, let’s talk about cron, which is a scheduled execution tool under Linux. Users other than root can use the crontab tool to configure cron tasks. All user-defined crontabs are saved in the /var/spool/cron directory and executed using the identity of the user who created them. To create a crontab entry as a user, log in as that user, and then type the crontab -e command to edit the user's crontab. This file uses the same format as /etc/crontab. When the changes to the crontab are saved, the crontab file is saved according to the username and written to the file /var/spool/cron/username. The cron daemon checks the /etc/crontab file, etc/cron.d/ directory, and /var/spool/cron directory for changes every minute. If changes are found, they are loaded into memory. This way, you don't have to restart the daemon when a crontab file changes.
Install crontab:
yum install crontabs
Instructions:
/sbin/service crond start //Start the service
/sbin/service crond stop //Close the service
/sbin/service crond restart //Restart the service
/sbin/ service crond reload //Reload configuration
View crontab service status: service crond status
Manually start the crontab service: service crond start
Check whether the crontab service has been set to start at boot, execute the command: ntsysv
Add automatic startup at boot:
chkconfig –level 35 crond on
crontab command:
Function description: Set timer.
Syntax: crontab [-u
Additional explanation: cron is a resident service that provides a timer function, allowing users to execute preset instructions or programs at a specific time. As long as the user can edit the timer configuration file, the timer function can be used. The configuration file format is as follows:
Minute Hour Day Month DayOFWeek Command
Parameters:
-e Edit the timer settings for this user.
-l List the timer settings for this user.
-r Delete the timer settings for this user.
-u
crontab format:
Basic format:
Minutes Hours Days Months Weeks Commands
*
The first column represents minutes 1 to 59. Each minute is represented by * or */1The second column represents hours 1 to 23 (0 represents 0 o'clock)
The third column represents dates 1 to 31
The 4th column represents the month 1~12
The 5th column identifies the week 0~6 (0 means Sunday)
The 6th column represents the command to be run
“*” represents a number within the value range,
“/” represents “every”,
“-” represents from a certain number to a certain numbers,
"," separates several discrete numbers
# +————- minute (0 – 59)
# | +————- hour (0 – 23)
# | | +——- day of month (1 – 31)
# | | | +——- month (1 – 12)
# | | | | +——- day of week (0 – 7 ) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
(1) First example.
30 21 * * * /etc/init.d/nginx restart
Restart nginx at 21:30 every night.
* * * * * /usr/bin/php -f /root/test.php >> test.log
Execute the /root/test.php file every minute and output the results to test.log.
After completing the above basic work, let’s take a look at how to use crontab to execute PHP scripts regularly:
(1) I created a new test.php file under /root with the following content:
echo date('Y-m-d H:i:s')."from http://www.phpddt.com n";
?>
(2) Then crontab -e writes the following shell:
Note: test.php must be an executable file: chmod +x test.php
The test results are normal, the screenshot is as follows:
Of course you can use crontab -e to continue adding tasks. You can see a root file under /var/spool/cron.
Use Windows to schedule tasks directly under Windows, and just open the web page through bat. It is not copied like Linux.

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

PHP sessions have a significant impact on application performance. Optimization methods include: 1. Use a database to store session data to improve response speed; 2. Reduce the use of session data and only store necessary information; 3. Use a non-blocking session processor to improve concurrency capabilities; 4. Adjust the session expiration time to balance user experience and server burden; 5. Use persistent sessions to reduce the number of data read and write times.

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
