How to parse SOAP response with PHP?

Servers: Why won't my cronjob execute?

  • I am trying to run a cronjob once or twice a day on my server and I get this error: php/updateIcon.php: line 1: ?php: No such file or directory php/updateIcon.php: line 2: syntax error near unexpected token `'myConnectDB.inc.php'' php/updateIcon.php: line 2: `require_once('myConnectDB.inc.php');' my php file I am trying to run is: <?php require_once('myConnectDB.inc.php'); session_start();   //get all the beers @ $db = new myConnectDB(); $query = "SELECT * FROM uniqueBeers"; $resultBeer = $db->query($query); $uNum = $resultBeer->num_rows; //cycle through beers and print    for( $i = 0; $i < $uNum; $i++){ $row = $resultBeer->fetch_assoc(); //get beer id $id = $row['beerID']; $brewID = $row['breweryID']; //get beer icon //get icon //construct url and get xml $uri = "http://api.brewerydb.com/v2/beer/%24id?key=xxxxxxxx&format=json"; $response = file_get_contents($uri); //parse xml $myBeer = json_decode($response); $icon = $myBeer->data->labels->medium; //sql statement to update @ $db2 = new myConnectDB(); $query2 = "UPDATE uniqueBeers SET icon = '$icon' WHERE beerID = '$id' "; $resultBeer2 = $db2->query($query2); //do same for brewery icon $uri3 = "http://api.brewerydb.com/v2/brewery/%24brewID?key=xxxxxx&format=json"; $response3 = file_get_contents($uri3); //parse xml $myBrew = json_decode($response3); $iconBrew = $myBrew->data->images->medium; //sql statement to update @ $db3 = new myConnectDB(); $query = "UPDATE uniqueBeers SET brewIcon = '$iconBrew' WHERE breweryID = '$brewID' "; $resultBeer3 = $db3->query($query3);     } ?>

  • Answer:

    looks like it's trying to run it as a shell script. you could do what martin suggested, or add "#!/usr/local/bin/php -f" as the first line in your php script (of course adjust this if the "php" program is found at a different path on your system).

Bhu Boue Vidya at Quora Visit the source

Was this solution helpful to you?

Other answers

Ok, short answer, in your crontab, on the line with the script, add "php" directly before the script filename, like this (the beginning of your line will differ depending on the time(s) of day you want it to execute:) 0 0 * * * root php myscript.php Long answer, when the shell goes to execute a script or program, it checks whether the filename provided is a binary file. If it is, it is executed as a native program. If it is not, the shell expects the first line to specify the interpreter, like this: #!/bin/bash This specifies that /bin/bash should be used to execute the script. When you don't specify an interpreter, you get errors like you pasted. By modifying the line as I specified the PHP interpreter is called and the script is provided as a command line argument to it.

Marty Gottesfeld

Always run scripts at command line manually before adding them to cron, this well help you to understand your scripts better and elimiate errors if any. Testing is important dont forget. For solving your issue you can follow Martin's suggestion.

Vineet Daniel

use absolute paths in cronjobs. check your paths in general. man cronjob. for example: in the cronjob you point to "/full/path/doit.php". in doit.php you could add something like that to get the full path for all the following scripts: define('APP_ROOT', dirname(__FILE__)); i think that should get you the idea.

Noname but Honest

You get that error because PHP fails to load "myConnectDB.inc.php" file, you'll need to set the correct path to make it works

Nidhal Machta

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.