Back-end execution

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Back-end execution

Post by JellyFish »

How do I execute PHP scripts on my server? What are all the possible ways of doing this? I know that when some one request a php file on my server that it is run. But how do run a php file without the a request from a remote location?

What I would like to do is have a schedule when a file is to be run.

Hopefully you understand what I'm trying to say.

Thanks for reading. All help is appreciated. :D
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

cron jobs?
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

thiscatis wrote:cron jobs?
What?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Linux OS:

You can either run:

Code: Select all

php file.php
or include

Code: Select all

#!/usr/local/bin/php

on the top of your php file. (check the path to php executables!)

make it executable:

Code: Select all

chmod 0755 file.php
and run it:

Code: Select all

./file.php
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

JellyFish wrote:
thiscatis wrote:cron jobs?
What?
This is one of those times where it's okay to say google it
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

man at
At allows fairly complex time specifications, extending the POSIX.2 standard. It accepts times of the form HH:MM to run a job at a
specific time of day. (If that time is already past, the next day is assumed.) You may also specify midnight, noon, or teatime (4pm)
and you can have a time-of-day suffixed with AM or PM for running in the morning or the evening. You can also say what day the job
will be run, by giving a date in the form month-name day with an optional year, or giving a date of the form MMDDYY or MM/DD/YY or
DD.MM.YY. The specification of a date must follow the specification of the time of day. You can also give times like now + count
time-units, where the time-units can be minutes, hours, days, or weeks and you can tell at to run the job today by suffixing the time
with today and to run the job tomorrow by suffixing the time with tomorrow.
man crontab
crond is responsible for scanning the crontab files and running their commands at the appropriate time. The crontab program communi-
cates with crond through the "cron.update" file which resides in crontabs directory, usually /var/spool/cron/crontabs. This is accom-
plished by appending the filename of the modified or deleted crontab file to "cron.update" which crond then picks up to resynchronize
or remove its internal representation of the file.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

You guys lost me. :?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Maybe your are asking for this - viewtopic.php?t=72282
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

VladSun wrote:Maybe your are asking for this - viewtopic.php?t=72282
I'm not really, as I don't understand that post.

I googled Cron and got a bunch of pages I don't understand about it. I'm finding myself not knowing much about servers when that's the guts of a website.

Where's the best place to learn everything there is to know about web servers explained in simple English terms, still explaining server terminology, and how to administrate them?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

1. Do you use hosting services or you have your own server?
2. If you use hosting services are you allowed to use SSH?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

VladSun wrote:1. Do you use hosting services or you have your own server?
2. If you use hosting services are you allowed to use SSH?
  1. I'm on a shared hosting server.
  2. I don't know. I don't know what SSH is.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

JellyFish wrote:
  1. I'm on a shared hosting server.
  2. I don't know. I don't know what SSH is.
Shared hosts usually don't offer SSH.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

superdezign wrote:Shared hosts usually don't offer SSH.
Hm, in my country SSH is not offered only for the cheapest plan ...
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

VladSun wrote:
superdezign wrote:Shared hosts usually don't offer SSH.
Hm, in my country SSH is not offered only for the cheapest plan ...
Then I've yet to come across the shared host's that do.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

A weird solution to your problem is to use exec() and put it in background...

main.php:

Code: Select all

<?php
exec("/usr/local/bin/php -q ".realpath()."/child.php &");
?>
child.php:

Code: Select all

<?php
while (true)
{
        // some actions here
	sleep(10); // sleep for 10 seconds
}
?>
Then you call the main.php from your browser and close it. The child.php is being executed forever ... I am not sure whether you need to set the maximum execution time of child.php by using http://www.php.net/set_time_limit with zero argument value .
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply