Is PHP suitable for very large projects? Can it be safe for transactions?

This question may seem strange.

But every time I did PHP projects in the past, I came across such a bad experience:

Scripts stop working after 10 seconds. This leads to very poor database inconsistency (a bad example for the delete cycle: the user is about to delete the photo album. The album object is deleted from the database, and then halfway down the photo deletion script will be killed right where it is, and 10,000 photos left without a link )

It is not safe for transactions. I have never found a way to do something reliably to do this. If the script is killed, it will be killed. Right in the middle of the cycle. He's just killed. This has never happened with tomcat with java. Java works, starts and starts if it takes a long time.

Many newsletter scripts try to solve this problem by breaking the work into many packages, that is, sending 100 at a time, then rewriting the page (oh man really silly), doing the next one, and soon. Most often, something hangs, or the script takes more than 10 seconds, and your platform is damaged.

But then I hear that very large projects use PHP, for example studivz (German Facebook clone, in fact the largest German site). So, there is a tiny light of hope that this bad behavior comes only from unprofessional hosting companies that just kill php scripts because their servers are so bad. What is the truth about this? Can it be configured in such a way that scripts will never be killed because they take a little longer?

+3
source share
11 answers

Is PHP suitable for very large projects?

, , . ? , . , . , , , , , , , / .. ..

, , , , . , , . , . (, ).

+14

, , Zend Framework. , 10 , , http://de3.php.net/set_time_limit

PHP: Facebook, Wikipedia, StudiVZ, Digg.com .. , , - , , ?

+6

- , , . .

10K, , .

  • : , .
  • : .
  • : .
+3

php, :

mysql_query("BEGIN");

/// do your queries here

mysql_query("COMMIT");

commit .

- , :

mysql_query("ROLLBACK");

: . , , , InnoDB

+2

, script, php.ini, ini_set/set_time_limit

+1

, ( Facebook), Facebook, PHP. Digg. Yahoo. , .

ignore_user_abort - , , , , . , , / , ... / - , .

+1

, 1000 , ignore_user_abort set_time_limit.
- :

ignore_user_abort(true); //users leaves webpage will not kill script
set_time_limit(0); //script can take as long as it wants
for(i=0;i<10000;i++)
 costly_very_important_operation();

, , script :

ignore_user_abort(true); //users leaves webpage will not kill script
set_time_limit(0); //script can take as long as it wants
while(true)
  do_something();

, script , .

time_limit 0.

0

, , . , script/ , - .

- , , . PHP, , , , script.

, , "" -, , script. PHP-, , , . AJAX , script.

, "" PHP, - Apache:

exec("nohup /usr/bin/php -f /path/to/script.php > /dev/null 2>&1 &");

, PHP . PHP , , "" , , . , , , .

, Java , . PHP. PHP . , , PHP, , ?

0

, , , , , MyISAM mysql ( ). InnoDB, . postgreSQL.

0

Many, many software sites are created in PHP. However, you will not hear about millions of web pages made in PHP that no longer exist because they were abandoned. These pages may have burned all of the company's money because they ran into a mess in PHP, or maybe they went bankrupt because their soft was so crappy that the client didn't want it ... PHP seems good at startup, but it doesn't scale very well. Yes, there are many huge websites in PHP, but they are more likely to be exceptions than normal.

-1
source

Source: https://habr.com/ru/post/1709510/


All Articles