From owner-freebsd-questions@FreeBSD.ORG Sun Jan 17 20:01:49 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA659106568B for ; Sun, 17 Jan 2010 20:01:49 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.24]) by mx1.freebsd.org (Postfix) with ESMTP id 91EE48FC18 for ; Sun, 17 Jan 2010 20:01:49 +0000 (UTC) Received: by qw-out-2122.google.com with SMTP id 5so492864qwd.7 for ; Sun, 17 Jan 2010 12:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Rkb/LVlZ0OCfTFOG5PYTmzP2+fV/L7hxbNEnu+VN7rk=; b=WfLlMZGYk+O4y3jgo8anLvytrrBBFvsJnuyVdoJ0Z575/6iu2tCjXXZy0oIlaZDcoP qaikNPqpyvqV3+yWas3PLC8W5sGraFVC/wXwsXUQDsIwDsR8YrHXKS89YPauyodEx3zo GamW0Y7c6Z/MBO0mH6Ez04qUQHXfNfdG8N+I4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=sNIGBGHfYnKd7CAuJujg4VjhOnjZb6tSnGxCDjMoPg3VhDLsfO5+WxEPsLeYa4CiGr 77/4mO1xKIQ+UkEdCU0LQ2Hb5m6M2RJ23StigS/GD1404U8135n0eF+JQsIpG5qzdFIE qKFQ7lunSdX+qsiXW+8mEdwtTNI/9AGpXj9Ac= MIME-Version: 1.0 Received: by 10.229.34.143 with SMTP id l15mr3483579qcd.80.1263758508263; Sun, 17 Jan 2010 12:01:48 -0800 (PST) In-Reply-To: References: Date: Sun, 17 Jan 2010 12:01:48 -0800 Message-ID: <560f92641001171201t37f5a123m3b59ff4ce6e007e3@mail.gmail.com> From: Nerius Landys To: Diego Montalvo Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-questions@freebsd.org, MaJ Subject: Re: Running PHP File under Crontab... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jan 2010 20:01:49 -0000 > I am wanting to execute a PHP file 5 times a day via crontab. Is it > possible? =A0If so what is the proper crontab command for this? Hi. I'm running several PHP programs via cron. #1 Make sure you have CLI (command line interface) in your PHP port: As root, > cd /usr/ports/lang/php5 > make config Then make sure the "CLI" is set to "on". If it isn't, change it, and recompile the port. For example "portupgrade -f php5-5.2.12" will recompile the port, if you have portupgrade installed. #2 Write the PHP script you want to run. There are different syntaxes for writing a command-line PHP program but here is one of them: Save this to a path "/path/to/mycode.php". #3 Add cron job to execute this program. Your crontab should look like this: */5 * * * * /usr/local/bin/php -f /path/to/mycode.php (That would execute your PHP script every 5 minutes for example.) That's it! There is an alternate way to write PHP scripts for CLI, but I have not used it extensively, so I don't know all the details or the correctest way to do it. You can write a script like this: #!/usr/local/bin/php And then save it to a file for example "test.php" and set the executable permission on it. Then you can just: ./test.php from a terminal. So you could change the cron to just execute the script directly in this case instead of explicitly calling /usr/local/bin/php in the crontab.