Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic server.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I've been surfing the web for quite a while now but haven't found what I am looking for. I'm looking for a script that doesn't have to be activated by a visitor, but keeps running on the server. I'd like to store the data that my script gets from other pages.

If you look at , you'll see that it's a financial site that displays headlines from leading financial newspapers. The script is working fine, but, however, it takes to long to load. If I just can get a script that stores the data every minute, the visitor doesn't have to wait on the other servers. I just have to open one single file that is stored on my own server, therefor the loading time will be decreased.

Please help me if you can, and if you know the right word for it, don't hesitate to anwser!

Dijksma
 
Create your processing script (the one that you will use to process the data and store it) as a shell script (use #!/path/to/php/binary -q in the shebang line as such:

#!/usr/local/lib/php -q
<?php
//my script
?>

then write a simple shell script that will run your script with a 1 minute time delay between runs like this:

#!/bin/sh

while sleep 60
do
./myprocessingscript.php
done

OR you can create a crontab entry like this:

`crontab -e` (edit your crontab)

and place the following into the file:

* * * * * /path_to_my_processing_script.php

this will run your script persistently (in essence) and will process your data continuously so you are never lagging.

Just be sure to watch the processes and see if there is anything running out-of-control (ps -augx).

Let me know if this does not work or if you need further assistance.

Chad.
 
THX,

I made this (simple) script:
---
<?
$leeg = &quot;&quot;;
$file = fopen(&quot;store.inc&quot;,&quot;w+&quot;);
fputs($file, $leeg);
fclose($file);

?>


<?

echo '<center><B>Het Financiele dagblad</B></center>';
$fileArray = file(&quot;
if ( ! $fileArray ) {
echo '<tr><td>The news interface is down for maintenance.</td></tr>',
'</table></body></html>';
break;
}

$searchStr ='<tr><td class=&quot;tekstregulargrey&quot;>';
$i = 0;
foreach($fileArray AS $line) {
if ( strstr($line, $searchStr) ) {
$line = str_replace(&quot;ShowNews.asp?&quot;, &quot; $line );
echo $line, &quot;\n&quot;;

$i++;
}


if ( $i == 1 ) {
$een = $line;
}

if ( $i == 2 ) {
$twee = $line;
}

if ( $i == 3 ) {
$drie = $line;
}

if ( $i == 4 ) {
$vier = $line;
}

if ( $i == 5 ) {
$vijf = $line;
}

if ( $i == 6 ) {
$zes = $line;
}

if ( $i == 7 ) {
$zeven = $line;
}

if ( $i == 8 ) {
$acht = $line;
}

if ( $i == 9 ) {
$negen = $line;
}
if ( $i == 10 ) {
$tien = $line;
break;
}
}
echo '<BR><BR><BR>';

?>
<?
$totaal = &quot;$een $twee $drie $vier $vijf $zes $zeven $acht $negen $tien&quot;;


$file = fopen(&quot;store.inc&quot;,&quot;w+&quot;);
fputs($file, $totaal);
fclose($file);
?>
---
I know this script is really primitive, but it does the trick. When i tried to write it down another way, it only saved the last sentence. BIt anyway, this is the script i would like to run automaticaly.

I'm not sure if I get what you just said, could you show me what i need to add / chance in the script so it will do her task automatically?
 
Okay,

First, if you have telnet access, login to your server and run the following command:

whereis php

you should get something like:

/usr/local/bin/php /usr/local/lib/php (and so one).....

If you do have what is shown above, you are in perfect shape to do (add the shebang line):


#!/usr/local/bin/php -q
<?
$leeg = &quot;&quot;;
$file = fopen(&quot;store.inc&quot;,&quot;w+&quot;);
fputs($file, $leeg);
fclose($file);

?>

..........


Now create a new script that will be just a very basic shell script like this:

#!/bin/sh
# myshellscript - execute the script every X seconds
# by Chad Horton, 2001.07.09 10:40
#
# usage:
# myshellscript 60

if [ $# -lt 1 ]
then
echo >&2 &quot;usage: myshellscript [interval]&quot;
exit 1
fi

eval &quot;/path/to/script/myscript.php&quot;
while sleep $@
do
eval &quot;/path/to/script/myscript.php&quot;
done


and save, upload in ASCII form to your server, set permissions to 755 for both your php script and this shell script (make sure to place this script outside documentroot so it won't be accessible to the public) and while still logged into telnet, go to the location of this shell script and run it:

nohup ./myshellscript 60 &

(yes type in everything above on the command line while still logged in to your server. This will allow you to get to another command line and also makes it so that all garbage or whatever other output you have from your script will write to a file called nohup.out (which you can view for your pleasure at any time).

This will automatically run your php script every 60 seconds. You can make the script run on any interval you want just by changing the number of seconds when you run the script.

If you still need assistance, just let me know and I will provide whatever help you may need to get this fully integrated.

Sincerely,
Chad.
 
Thank you, i'll give it a try tomorrow, i'll let you know if i have any questions.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top