1--TEST-- 2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - access/update file through softlink 3--SKIPIF-- 4<?php 5if (PHP_OS_FAMILY === 'Windows') { 6 require_once __DIR__ . '/windows_links/common.inc'; 7 skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__); 8} 9?> 10--FILE-- 11<?php 12/* Variation 3 : Create file and a soft link to the file 13 Access data of the file through the soft link 14 Update the file through soft link 15 Check size of file and soft link link 16*/ 17 18$file_path = __DIR__; 19echo "*** Accessing and updating data of file through soft link ***\n"; 20// Creating file and inserting data into it 21$filename = "$file_path/symlink_link_linkinfo_is_link_variation3.tmp"; 22 23// create temp file 24$file = fopen($filename, "w"); 25 26// create soft link to file 27$linkname = "$file_path/symlink_link_linkinfo_is_link_link_variation3.tmp"; 28var_dump( symlink($filename, $linkname) ); 29// storing size of symlink in a local variable 30$link_stat = lstat($linkname); // lstat of link 31$link_size = $link_stat[7]; // size of soft link 32 33// fill data into file 34fwrite($file, str_repeat("text", 20) ); 35fclose($file); 36 37echo "\n-- Access data of the file through the soft link --\n"; 38$data_from_link = file_get_contents($linkname); // data read from $filename 39var_dump( $data_from_link ); 40 41echo "\n-- Check size of soft link and file --\n"; 42var_dump( filesize($filename) ); 43var_dump( filesize($linkname) ); 44 45// taking lstat of symlink 46$stat = lstat($linkname); 47// checking that size of symlink remains same 48if ($link_size == $stat[7]) 49 echo "\nSoft link size remains same \n"; 50else 51 echo "\nWarning: Soft link size has changed \n"; 52 53echo "\n-- Updating file with data through soft link --\n"; 54// append link with data 55$fp = fopen($linkname, "a"); // open in append mode 56fwrite($fp, "Hello World"); 57fclose($fp); 58 59// now check temp file for data; it should append "Hello World" 60$data_from_file = file_get_contents($filename); 61var_dump( $data_from_file ); 62 63echo "\n-- Check size of soft link and file --\n"; 64var_dump( filesize($filename) ); 65var_dump( filesize($linkname) ); 66 67// taking lstat of symlink 68$stat = lstat($linkname); 69// checking that size of symlink remains same 70if ($link_size == $stat[7]) 71 echo "\nSoft link size remains same \n"; 72else 73 echo "\nWarning: Soft link size has changed \n"; 74 75echo "\n-- Updating file with data and check data through soft link --\n"; 76// write to temp file 77$file = fopen($filename, "w"); 78fwrite($file, "Hello World"); 79fclose($file); 80 81// now check link for data; it should echo "Hello World" 82$data_from_link = file_get_contents($linkname); 83var_dump( $data_from_link ); 84 85echo "\n-- Check size of soft link and file --\n"; 86var_dump( filesize($filename) ); 87var_dump( filesize($linkname) ); 88 89// taking lstat of symlink 90$stat = lstat($linkname); 91// checking that size of symlink remains same 92if ($link_size == $stat[7]) 93 echo "\nSoft link size remains same \n"; 94else 95 echo "\nWarning: Soft link size has changed \n"; 96 97// delete the link 98unlink($linkname); 99// delete the temporary file 100unlink($filename); 101 102echo "Done\n"; 103?> 104--EXPECT-- 105*** Accessing and updating data of file through soft link *** 106bool(true) 107 108-- Access data of the file through the soft link -- 109string(80) "texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext" 110 111-- Check size of soft link and file -- 112int(80) 113int(80) 114 115Soft link size remains same 116 117-- Updating file with data through soft link -- 118string(91) "texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttextHello World" 119 120-- Check size of soft link and file -- 121int(91) 122int(91) 123 124Soft link size remains same 125 126-- Updating file with data and check data through soft link -- 127string(11) "Hello World" 128 129-- Check size of soft link and file -- 130int(11) 131int(11) 132 133Soft link size remains same 134Done 135