Jump to content

Chris92

Members
  • Posts

    206
  • Joined

  • Last visited

About Chris92

  • Birthday 03/19/1992

Contact Methods

  • Website URL
    http://chrishemmens.com

Profile Information

  • Gender
    Male
  • Location
    Netherlands

Chris92's Achievements

Member

Member (2/5)

0

Reputation

  1. Well then I might as well just right it out in an if rather than a try statement and not bother catch it. Can you only catch ErrorExceptions in PHP?
  2. Is there any way to catch warnings without defining a warning handler? Example: try { $settings = parse_ini_file( 'main.ini' ); } catch( ErrorException $e ) { throw new ErrorException('No main configuration file found for webiste', '0003'); } Only ends up throwing a warning if the file doesn't exist. I want to catch it and throw an error.
  3. read the PHP documentation, he posted links on the functions. mkdir() makes a new directory: http://php.net/mkdir fopen() starts a new file stream: http://php.net/fopen once you have started a new stream you can write to it using fwrite(): http://php.net/fwrite and save it using fclose(): http://php.net/fclose I'll write you a small script: <?php $dir = 'myDir'; $file = 'myFile.php'; // check the directory to see if it already exists if( is_dir($dir) === false ) { // if it doesn't make a new directory mkdir($dir); } // start a new stream $f = fopen($file, 'w'); // 'w' for write // write the php to the stream fwrite( $f, '<?php echo "Hello world!"; ?>' ); // close the stream fclose($f); // include our new php script to see if it's working: include $myDir . '/' . $myFile; // Hello world! ?>
  4. You could get the file contents and then echo them along with a different header. <?php header('content-type: image/jpg'); echo file_get_contents('C:/MYFolder/SubFolder/Image.jpg'); ?> Or rather than even need to call the php script, base64 encode it and use that as the url (wouldn't recommend either). <?php $image = file_get_contents('C:/MYFolder/SubFolder/Image.jpg'); $base64 = base64_encode($image); echo '<img src="data:image/jpg;base64,'. $base64 .'" alt="" />'; ?>
  5. It's for a web game. The thing is the game has to be accessible by an API, for cross platform compatibility, so I'm storing everything in a database rather than a cache system. The web application works like any other typical web system would. It sends data through one Ajax request and gets it through another. The getting part uses reverse-ajax. So the client doesn't poll the server when there's no need for it. Then the server runs a PHP script that polls the MySQL server for updates which then returns the new values to the HTTP server which then returns data to the client. I have read up on PostgreSQL and it has listen and notify functionality. Does MySQL not come with the same?
  6. So the answer is no? The only way is polling?
  7. Wasn't really what I was looking for. It just explains reverse-ajax. What I'm looking is more of a MySQL to PHP push technique. Not PHP to JavaScript. What my PHP script does is this: $query = mysql_query("SELECT * FROM `table` WHERE `time` > ". (int)$_SESSION['last_package_time'] .""); $rows = mysql_num_rows($query); while( $rows == 0 ) { $query = mysql_query("SELECT * FROM `table` WHERE `time` > ". (int)$_SESSION['last_package_time'] .""); $rows = mysql_num_rows($query); set_time_limit(1); usleep(250000); } echo json_encode(mysql_fetch_assoc($query)); Which as you can see is rather straining on the MySQL server. There's bound to be a way for MySQL to not return a value until the query has a value.
  8. Is there an alternative to polling a MySQL database? Basically I have a PHP script that polls a table every half a second. This script then returns a value to a client that is doing a reverse-ajax request on the server. Is there a different technique that can be used, so MySQL doesn't return until there is an update rather than polling for an update. Thanks in advance, Chris
  9. You need to port forward port 80 to your local address on your router.
  10. Just to throw even more anoyingness to this thread: $var = 5; $i = 1; while( $i <= $var ) { echo $i . "<br />\n"; $i++; }
  11. I made a nice solution, here's an example: <?php class twitter { var $v = "Hi"; function tweets($i, $b) { return $this->v . $i ."? ". $b; } } $str = "twitter_tweets(5, true)"; $plugin = explode( "_", $str, 2 ); // array( [0] => twitter, [1] = tweets(5, true) ) $func = explode( "(", $plugin[1], 2 ); // array( [0] => tweets, [1] => 5, true) ) $args = substr( $func[1], 0, (strlen($func[1])-1) ); // 5, true $args = explode( ",", $args ); // array( [0] => 5, [1] => true ) // trim whitespace in arguments foreach( $args as $key => $val ) { $args[$key] = trim($val); } $$plugin[0] = new $plugin[0]; // $twitter = new twitter echo call_user_func_array( array( $$plugin[0] , $func[0] ), $args ); // $twitter->tweets(5,true) ?>
  12. PHP isn't Perl. function parimeter($length, $width) { return 2 * ($length + $width); } $parimeter = parimeter($length, $width); echo "parimeter: . $parimeter";
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.