目前我使用的是 https://github.com/erusev/parsedown 来解析Markdown
现有两种选择:
1. 在插入数据库前解析
2. 输出时解析
哪种更好些
回复内容:
目前我使用的是 https://github.com/erusev/parsedown 来解析Markdown
现有两种选择:
1. 在插入数据库前解析
2. 输出时解析
哪种更好些
输出时解析, 顺便如果有伪静态的话, 可以生成真正的静态文件, 这样下次就去请求生成的html了, 不再读数据库和走解析的流程, 更新数据的时候只需要删除原来生成的静态文件, 再次触发访问 就可以重新生成.
如果没有伪静态可以采取使用cache(最简单的文件形式的)
的方式,访问时先检测cache
目录中是否有对应的已经生成好的html文件,如果有就直接输出,当在后台更新数据时,删除cache
目录中相应的文件,或者直接清空cache
目录,下次访问时就会重新生成.
使用前端js
对Markdown
的内容进行解析,需要浏览器去加载相应的js
,由js
去完成转换,中间需要相应的时间,且页面多加载需要解析Markdown
的js文件(多了一个HTTP
请求), 不如后端解析后生成相应的html
文件,下次直接使用,来得实在.
且不用考虑浏览器是否支持js :)
当然是输出的时候解析(可以缓存下)
你入库之前解析的话,如果要编辑了怎么办?
再反过了?
综合考虑 当然是两份啦。md一份,解析一份。展示的时候取解析好的那一份。
当然输出时解析也行。但是计算机资源瓶颈一般在计算能力上。何必在展示的时候浪费呢。
输出的时候解析,用marked.js
即可
你也可以考虑前端解析。
存储解析后数据的话,如另外一个答案所说无法对原文本进行编辑。
存两份的话多占了空间还得同步。
而前端解析的话这些问题都不存在了,反正前端在编辑的时候也是要看预览版的,不如把工作都放在前端,后端只存原本。

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.


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

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

Notepad++7.3.1
Easy-to-use and free code editor
