Ik werk nu al een week aan onderstaande code. De code zorgt op een site van mij voor het genereren van .js bestandjes met een code die voor links zorgt op een website. De links worden uit de database gehaald als het cache .js bestandje nog niet op de server aanwezig is. Ik voeg me af of ik zoiets ook makkelijker kan en minder server belastend? Er moeten per dag ALTIJD 100 links verschijnen. Dus mocht er van de ene categorie "1" bijv niets in de database staan moet ie doorgaan naar 2 enz. De laatste mag 2x zoveel voorkomen als de anderen.
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
| setlocale (LC_ALL, 'nl_NL'); $strGotd=strftime ("%e %B %Y", mktime(0,0,0,date("m"),date("d")-0,date("Y"))); $todayTitel=strftime ("%A %e %B %Y", mktime(0,0,0,date("m"),date("d")-0,date("Y"))); $strDatum0=date("Ymd",mktime(0,0,0,date("m"),date("d"),date("Y"))); $strDatum1=date("Ymd",mktime(0,0,0,date("m"),date("d")-1,date("Y"))); $strDatum2=date("Ymd",mktime(0,0,0,date("m"),date("d")-2,date("Y"))); $strDatum3=date("Ymd",mktime(0,0,0,date("m"),date("d")-3,date("Y"))); $strFilename1 = '/home/httpd/vhosts/*********.nl/httpdocs/cache/T'.$strDatum1.'.js'; $strFilename2 = '/home/httpd/vhosts/*********.nl/httpdocs/cache/T'.$strDatum2.'.js'; $strFilename3 = '/home/httpd/vhosts/*********.nl/httpdocs/cache/T'.$strDatum3.'.js'; // DAG 0 for($i=0;$i<3;$i++) { if ($i == "0") { $strFilename = '/home/httpd/vhosts/*********.nl/httpdocs/cache/T'.$strDatum0.'.js'; $strDatumList=strftime ("%e %B", mktime(0,0,0,date("m"),date("d")-0,date("Y"))); } elseif ($i == "1") { $strFilename = '/home/httpd/vhosts/*********.nl/httpdocs/cache/T'.$strDatum1.'.js'; $strDatumList=strftime ("%e %B", mktime(0,0,0,date("m"),date("d")-1,date("Y"))); } elseif ($i == "2") { $strFilename = '/home/httpd/vhosts/*********.nl/httpdocs/cache/T'.$strDatum2.'.js'; $strDatumList=strftime ("%e %B", mktime(0,0,0,date("m"),date("d")-2,date("Y"))); } else { $strFilename = '/home/httpd/vhosts/*********.nl/httpdocs/cache/T'.$strDatum3.'.js'; $strDatumList=strftime ("%e %B", mktime(0,0,0,date("m"),date("d")-3,date("Y"))); } if (!file_exists($strFilename)) { $dbcnx = mysql_connect("localhost", "*********", "********"); mysql_select_db("*********"); ob_start(); for ($r=1;$r<101;$r++) { srand((double)microtime()*10000000); $random = rand(1, 5); if ($random == "1") { //BLINDLINK $result = mysql_query("SELECT * FROM linkjes ORDER BY RAND() DESC LIMIT 0, 1"); $num_rows = mysql_num_rows($result); if ($num_rows == 0) { $random = "2"; } while ($row = mysql_fetch_array($result)) { $subject = $row["strOms"]; $length=strlen($subject); if($length>53) { $subject=substr($subject, 0, 50)."..."; } echo "link(\"". $strDatumList . "\",\"". $row["strGenre"] . "\",\"" . $row["strUrl"] ."\",\"<font color=red>". $subject ."</font>\");//B\n"; $ideetje = $row['id']; } } if ($random == "2") { // SPONCOR $result = mysql_query("SELECT * FROM linkjes WHERE strListed = '0' AND strSponcor = '1' ORDER BY 'id' DESC LIMIT 0, 1"); $num_rows = mysql_num_rows($result); if ($num_rows == 0) { $random = "3"; } while ($row = mysql_fetch_array($result)) { $subject = $row["strOms"]; $length=strlen($subject); if($length>53) { $subject=substr($subject, 0, 50)."..."; } echo "link(\"". $strDatumList . "\",\"". $row["strGenre"] . "\",\"" . $row["strUrl"] ."\",\"<font color=green>". $subject ."</font>\");//$\n"; $ideetje = $row['id']; mysql_query("UPDATE linkjes SET strListed = '1' WHERE id = '$ideetje';"); } } if ($random == "3") { // REFERERS if ($r >= "50") { $result = mysql_query("SELECT * FROM linkjes WHERE strListed = '0' AND strRefer = '1' ORDER BY 'id' DESC LIMIT 0, 1"); $num_rows = mysql_num_rows($result); if ($num_rows == 0) { $random = "5"; } while ($row = mysql_fetch_array($result)) { $subject = $row["strOms"]; $length=strlen($subject); if($length > 53) { $subject=substr($subject, 0, 50)."..."; } echo "link(\"". $strDatumList . "\",\"". $row["strGenre"] . "\",\"" . $row["strUrl"] ."\",\"<font color=yellow>". $subject ."</font>\");//@\n"; $ideetje = $row['id']; mysql_query("UPDATE linkjes SET strListed = '1' WHERE id = '$ideetje';"); } } } else { $result = mysql_query("SELECT * FROM linkjes WHERE strListed = '0' AND strSponcor = '0' AND strRefer = '0' ORDER BY 'id' DESC LIMIT 0, 1"); while ($row = mysql_fetch_array($result)) { $subject = $row["strOms"]; $length=strlen($subject); if($length > 53) { $subject=substr($subject, 0, 50)."..."; } echo "link(\"". $strDatumList . "\",\"". $row["strGenre"] . "\",\"" . $row["strUrl"] ."\",\"". $subject ."\");\n"; $ideetje = $row['id']; mysql_query("UPDATE linkjes SET strListed = '1' WHERE id = '$ideetje';"); } } } $output = ob_get_contents(); ob_end_clean(); $file = fopen($strFilename, "w"); fputs($file, $output); fclose($file); mysql_close(); } } $dbcnx = mysql_connect("localhost", "*********", "********"); mysql_select_db("*********"); mysql_query("UPDATE linkjes SET strListed = '0'"); mysql_close(); |